Westonci.ca makes finding answers easy, with a community of experts ready to provide you with the information you seek. Get expert answers to your questions quickly and accurately from our dedicated community of professionals. Discover in-depth answers to your questions from a wide network of professionals on our user-friendly Q&A platform.

A large hotel needs a program to store information about rooms at the hotel. Each of the rooms will be represented by an object which will store the number of beds in the room, and whether the room has a bath. Some rooms at the hotel are suites, in which case in addition to the information above they also need to store the number of sub-rooms in the suite. Which of the following is the best object-oriented program design?
a. Create a Suite class with the instance variables int numBeds, boolean hasBath, and int numSubrooms .Create a subclass Room of Suite which wil inherit the instance variables numBeds and hasBath from Room, but not the instance variable int numSubrooms
b. 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.
c. Create each of the following as separate classes, Room. Beds, Bath, Suite, SubRoom Create a single Roomor Suite class with the instance variables int numBeds, boolean hasBath, and int numSubrooms.
d. Create a Room class with the instance variables int numBeds, and boolean hasBath. Create a separate class Suite with the instance variable int numSubrooms

Sagot :

Answer:

b. 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.

Explanation:

In object-oriented program designs, applications are split into sub-tasks and each sub-task is designed by creating as one or more classes to model it. This allows for flexibility and extensibility among other things.

In the case of the large hotel, two classes are of utmost importance:

i. the Room class to hold information about the number of beds in the room and whether or not the room has a bath.

ii. the Suite class to hold, in addition to the information held by the Room class, information about the number of sub-rooms in the suite.

To apply the concept of object-oriented design, since the suite is a special type of room, the Room class will serve as the super class while the Suite class which contains extra information will serve as the subclass inheriting all the properties of the Room class. Therefore the Suite will have all the properties of the Room and also its own special property - number of sub-rooms in this case.