This question involves a system to manage hotel rooms available for occupancy. The rooms…
- User
This question involves a system to manage hotel rooms available for occupancy. The rooms are represented by the following HotelRoom class.
public class HotelRoom
{
/** Returns the number of beds in the room */
public int getNumBeds()
{ /* implementation not shown */ }
/** Returns the room number of the room */
public int getRoomNumber()
{ /* implementation not shown */ }
/** Returns true if the room is a suite and returns false otherwise */
public boolean isSuite()
{ /* implementation not shown */ }
/** Returns true if the room is available for occupancy and returns false otherwise
*/
public boolean isAvailable()
{ /* implementation not shown */ }
// There may be instance variables, constructors, and methods that are not shown.
}
Information about a hotel is stored in a Hotel object, which contains an array of rooms at the hotel. You will write two methods of the Hotel class.
public class Hotel
{
/** An array of all rooms at the hotel
- Guaranteed not to be null and to contain only non-null entries
*/
private HotelRoom[] rooms;
/** Returns the room number of an available room at the hotel, as described in part (a) */
public int chooseRoom(int numBeds, boolean wantSuite)
{ /* to be implemented in part (a) */ }
/** Returns the number of staff members needed to clean hotel rooms, as described in
- part (b)
*/
public int numberOfStaff()
{ /* to be implemented in part (b) */ }
// There may be instance variables, constructors, and methods that are not shown.
}
A programmer would like to add a method called getAllAffordableAvailableRooms, which returns a list of all rooms that are available for occupancy and cost less than a given amount.
Write a description of how you would change the HotelRoom and Hotel classes in order to support this modification.
Make sure to include the following in your response.
Write the method header for the getAllAffordableAvailableRooms method. Identify any new or modified variables, constructors, or methods aside from the getAllAffordableAvailableRooms method. Do not write the program code for this change. Describe, for each new or revised variable, constructor, or method, how it would change or be implemented, including visibility and type. You do not need to describe the implementation of the getAllAffordableAvailableRooms method. Do not write the program code for this change.
- Assistant
To support the modification of adding a getAllAffordableAvailableRooms method, the HotelRoom and Hotel classes would need to be modified as follows:
HotelRoom Class:
- A new private instance variable called costPerNight would need to be added to store the cost per night for the room. This variable would have a type of double.
- A new public method called getCostPerNight would need to be added to return the cost per night for the room. This method would have a return type of double.