Answered step by step
Verified Expert Solution
Question
1 Approved Answer
this assignment is an extension of a previous assignment and I provided the code for that assignment here. please answer using JAVA and add comments
this assignment is an extension of a previous assignment and I provided the code for that assignment here. please answer using JAVA and add comments for explanition. thanks
Previous assignment code
//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 Listrooms = 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 Listwalls = 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 ListallPaintings = 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()); } }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 List
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started