124k views
5 votes
Create each of the following as separate classes: Room, Beds, Bath, Suite, SubRoom. Create a single RoomOrSuite class with the instance variables int numBeds, boolean hasBath, and int numSubrooms. Create a Suite class with the instance variables int numBeds, boolean hasBath, and int numSubrooms. Create a subclass Room of Suite which will inherit the instance variables numBeds and hasBath from Room, but not the instance variable int numSubrooms. Create a Room class with the instance variables int numBeds, and boolean hasBath. Create a subclass Suite of Room which will inherit the instance variables of Room and has an additional instance variable int numSubrooms. Create a Room class with the instance variables int numBeds, and boolean hasBath. Create a separate class Suite with the instance variable int numSubrooms.

1 Answer

1 vote

Answer:

Step-by-step explanation:

The following is written in Java and creates each one of the classes as requested. They can be used as seperate files within the same package but for the sake of simplicity, I am adding them together in this answer.

class RoomOrSuite {

int numBeds;

boolean hasBath;

int numSubrooms;

}

class Room {

int numBeds;

boolean hasBath;

}

class Beds {

}

class Bath {

}

class Suite {

int numBeds;

boolean hasBath;

private int numSubrooms;

}

class SubRoom {

}

class RoomOfSuite extends Room{

}

class SuiteOfRoom extends Room {

int numSubrooms;

}

User Nuwan Indika
by
5.2k points