105k views
0 votes
Implement the room class, 2) write the constructor for building class such that it initializes rooms to an array of rooms according to the number of rooms and rooms area sizes given in rooms areas array. 3) a building can be a commercial one or a residential one. expand building class (inherit from building class) to define a new class called commercial building. the new class should have:

a. a new member variable called name of type string.
b. a setter and getter for the name member variable,
c. a constructor that receives number of rooms, rooms areas sizes array, and the name of the building.

User Gabriel H
by
8.5k points

1 Answer

3 votes

Final answer:

In a programming context, the answer involves implementing a Room class, a Building class with a constructor, and a CommercialBuilding subclass with additional features related to the building's name.

Step-by-step explanation:

The question asks us to create two classes in a programming context, the Room class and a Building class, along with its subclass, the CommercialBuilding. The Building class will have a constructor that initializes an array of room objects based on the number of rooms and their respective areas. For the CommercialBuilding subclass, we need to add a new variable for the building's name and provide corresponding setter and getter methods, as well as a constructor that includes arguments for the number of rooms, array specifying room sizes, and the building's name.

Example Code:

class Room {
// Room properties and methods
}
class Building {
Room[] rooms;
public Building(int[] roomAreas) {
rooms = new Room[roomAreas.length];
for(int i = 0; i < roomAreas.length; i++) {
rooms[i] = new Room(roomAreas[i]); // assuming Room has a constructor that takes area
}
}
}
class CommercialBuilding extends Building {
private String name;
public CommercialBuilding(int[] roomAreas, String name) {
super(roomAreas);
this.name = name;
}
public void setName(String name) {
this.name = name;
}
public String getName() {
return this.name;
}
}
User Cobie
by
7.9k points