Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please HELP Reposted because the previous answers were incorrect. this assignment is an extension of a previous assignment and I provided the code for that

Please HELP

Reposted because the previous answers were incorrect.

this assignment is an extension of a previous assignment and I provided the code for that assignment here. please answer it using java and add comments on the methods for an explanation. thanks for the help.

image text in transcribed

image text in transcribed

image text in transcribed

this Is the Previous assignment and the code that was done by Chegg expert

image text in transcribed

image text in transcribedimage text in transcribed //package MuseumPack; public class Entity { private String name; // private attribute of string type to store the name of the this entity public Entity(String entityName) { /** * this constructor takes a String parameter named "entityName" * and assign it to private attribute name */ name = entityName; } public String getName() { return name; } } 

Museum.java

//package MuseumPack; import java.util.ArrayList; import java.util.List; public class Museum extends Entity { private List rooms = new ArrayList(); // this private attribute stores all the Room objects in this list public Museum(String entityName) { /** * Because Museum class extends Entity class so call the base class constructor * to initialize the base class properties */ super(entityName); } public Room addRoom(String roomName) { // this method takes a String parameter and create its named Room object and adds it to the List rooms Room newRoom = new Room(roomName); rooms.add(newRoom); return newRoom; // and returns this newly created Room object } public List getPaintings() { /** * This method returns all paintings in all room's walls in this museum object * For that we loops for each room in this museum in rooms List * then for each room, we loop for each wall * and for each wall we add its paitings to allPaintings and return its */ List allPaintings = new ArrayList(); for (Room room : rooms) { for (Wall wall : room.getWalls()) { for (Painting painting : wall.getPaintings()) { allPaintings.add(painting); } } } return allPaintings; } } 

Room.java

//package MuseumPack; import java.util.ArrayList; import java.util.List; public class Room extends Entity { private List walls = new ArrayList(); // List attribute to store all the walls in this room public Room(String entityName) { // constructor calls base method super(entityName); } public List getPaintings() { /** * This method returns all paintings in this room * for that, we loop for each wall * and for each wall we add its paitings to allPaintings and return this Lists */ List allPaintings = new ArrayList(); for (Wall wall : walls) { for (Painting painting : wall.getPaintings()) { allPaintings.add(painting); } } return allPaintings; } public Wall addWall(String name) { // this method first create a new Wall object Wall newWall = new Wall(name); walls.add(newWall); // adds this newly created Wall object to walls return newWall; // returns newly created Wall object } public List getWalls() { return walls; } } 

Wall.java

//package MuseumPack; import java.util.ArrayList; import java.util.List; public class Wall extends Entity { private List allPaintings = new ArrayList(); // List attribute to store all the Painting objects public Wall(String entityName) { // constructor super(entityName); } public List getPaintings() { return allPaintings; } public void addPainting(Painting newPainting) { allPaintings.add(newPainting); } } 

Painting.java

//package MuseumPack; public class Painting extends Entity { private Wall paitingWall; public Painting(String entityName) { // constructor takes String parameter and initializes the base class property super(entityName); } public void setWall(Wall paintingWall) { this.paitingWall = paintingWall; // calling Wall member method addPainting() paintingWall.addPainting(this); } public String toString() { return "Painting "+this.getName() + " set on " + this.paitingWall.getName(); } } 

Main.java

//package MuseumPack; public class Main { public static void main(String[] args) { Museum museum = new Museum("M1"); Room room1 = museum.addRoom("r1"); Room room2 = museum.addRoom("r2"); Painting painting1 = new Painting("p1"); Painting painting2 = new Painting("p2"); Wall wall1 = room1.addWall("w1"); Wall wall2 = room2.addWall("w2"); painting1.setWall(wall1); painting2.setWall(wall2); System.out.println(wall1.getPaintings()); System.out.println(wall2.getPaintings()); System.out.println(room1.getPaintings()); System.out.println(room2.getPaintings()); System.out.println(museum.getPaintings()); } }

this is the output of the previous assignment and the output of this assignment is in the assignment paper

image text in transcribed

The Problem This is an extension of the first assignment. We extend the problem as below. The museum stores not just paintings, but also sculptures and old, precious documents. Sculptures are put in rooms and documents are stored in show cases. Add new classes to represent these additions: Sculpture, Document, and Showcase. Other changes include the following. 1) Add the following class: Exhibit with fields name, artist (both String type) and year (int). Have a constructor to store these values and getters and setters for all fields. 2) Make Painting, Document, and Sculpture extend Exhibit. 3) Change the Entity class to an interface with two methods public String getName(); public ListgetExhibits(); 4) Implement the Entity interface in an abstract class named MuseumEntity. The class has a constructor that has a single parameter: the name, which is stored in a field. The class implements getName(), but not getExhibits(). 5) The concrete classes Museum, Room, and Wall extend MuseumEntity Obviously, they have to implement the getExhibits() method. There is no getPaintings() methods in these classes anymore. a 6) Room and Wall have the method addExhibit(Exhibit exhibit). There is no addPainting(Painting painting) method anymore. 7) Make adjustments necessary to be able to compute the Exhibit objects in Room You will have to override toString() appropriately, throughout Use generics wherever applicable. Refer to the section below to better understand the functionality. A Minimal Test The following code shows an idea of the expected functionality. Please remember that I will exercise your program with a more extensive test. public class MyDriver { public static void main(String[] args) { Museum museum = new Museum ("M1"); Room room1 = museum.addRoom("1"); Room room 2 = museum. addRoom("r2"); Painting painting1 = new Painting("p1", "al", 1765); Painting painting2 = new Painting("p2" "a2", 1812); Wall wall1 = room1.addwall ("w1"); Wall wall2 = room2. addwall ("W2"); Showcase showCase = new Showcase ("showcase1"); showcase.setRoom(room1); Document document = new Document ("d1", "1", 1800); document.setShowCase(showCase); Sculpture sculpture = new Sculpture("s1", "a3", 1300); sculpture.setRoom(room); painting1.setWall(walli); painting2.setwall(wall2); System.out.println(painting1.getWal10); System.out.println(wall1.getExhibits()); System.out.println(wall2.getExhibits(); System.out.println(room.getExhibits()); System.out.println(room2.getExhibits()); System.out.println(museum.getExhibits(); 3 It produced the following output. wall wi [Painting Exhibit (name=p1, artist=al, year=1765) on wall wi] [Painting Exhibit (name=p2, artist=a2, year=1812) on wall w2] [Painting Exhibit (name=p1, artist=al, year=1765] on wall wi, Sculpture Exhibit [name=s1, artist=a3, year=1300) room ri, Document Exhibit (name=d1, artist=wi, year=1800] in Showcase showcasel room ril [Painting Exhibit (name=p2, artist=a2, year=1812] on wall w2] [Painting Exhibit [name-pl, artist=al, year=1765] on wall wi, Sculpture Exhibit (name=s1, artist=a3, year=1300) room ri, Document Exhibit [name=d1, artist=wi, year=1800] in Showcase showcasel room ri, Painting Exhibit [name=p2, artist=a2, year=1812) on wall w21 Documentation and Coding Conventions Follow the requirements described in the coding standards document under Assignments on D2L. Every class should be in a separate java file. Don't forget to document the constructors, Also, document the parameters and return values. The Problem A museum has a number of rooms, each of which has several walls. Paintings are exhibited on some or all the walls. Your task is to represent this system in an object-oriented manner. The museum, each room, each wall, and each painting has a name and each is represented in software by a class. This common property of the name is encapsulated in a super class named Entity; this class has a public constructor that takes the name of the entity as its only parameter. All other classes (Museum, Room, Wall, and Painting) are subclasses of Entity. Your system will thus have classes named Museum, Room, Wall, Painting, and Entity. The classes should be structured as shown below. Museum 1. A field to store the rooms 2. A constructor that sets the name 3. A method that returns a List (java.util) of Painting objects in the museum 4. A method to add a Room object. This method has a parameter for the name of the room and creates and returns the Room object created. Room 1. A field to store the walls 2. A constructor that sets the name 3. A method that returns a List (java.util) of Painting objects displayed in this room 4. A method to add a Wall object; This method has a parameter for the name of the wall and creates and returns the Wall object created. Wall 1. A field to store the paintings on this wall 2. A constructor that sets the name 3. A method that returns a List (java.util) of Painting objects displayed on this wall 4. A method to add a Painting object; this is called from the method (item 2) listed under Painting. Painting 1. A constructor that sets the name 2. A method to set the wall on which this painting is displayed; this calls the method (item 4) listed under Wall You will have to override toString() appropriately, throughout. Use generics wherever applicable. A Minimal Test The following code shows an idea of the expected functionality. Please remember that I will exercise your program with a more extensive test. public static void main(String[] args) { Museum museum = new Museum ("M1"); Room room1 = museum. addRoom("r1"); Room room2 = museum.addRoom("r2"); Painting painting1 = new Painting ("p1"); Painting painting2 = new Painting("p2"); Wall wall1 = room1.addWall("w1"); Wall wall2 = room2.addWall("w2"); painting1.setWall(walli); painting2. setWall(wall2); System.out.println(wall1.getPaintings()); System.out.println(wall2.getPaintings()); System.out.println(room1.getPaintings()); System.out.println(room2.getPaintings()); System.out.println(museum.getPaintings()); } It produced the following output. [Painting p1 on wall w1] [Painting p2 on wall w2] [Painting p1 on wall w1] [Painting p2 on wall w2] Rainting p1 on wall wi, Painting p2 on wall w2] [Painting p1 set on wall w1] [Painting p2 set on wall w2] [Painting p1 set on wall w1] [Painting p2 set on wall w2] [Painting p1 set on wall w1, Painting p2 set on wall w2]

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Mastering Real Time Analytics In Big Data A Comprehensive Guide For Everyone

Authors: Lennox Mark

1st Edition

B0CPTC9LY9, 979-8869045706

More Books

Students also viewed these Databases questions

Question

=+2. How does your message use nonverbal communication?

Answered: 1 week ago

Question

Answered: 1 week ago

Answered: 1 week ago