1. Engineering
  2. Computer Science
  3. code in java please 1 define the class hotelroom the...

Question: code in java please 1 define the class hotelroom the...

Question details

***Code in JAVA please***

1. Define the class HotelRoom. The class has the following private data members: the room number (int) and daily rate (double). Include a default constructor as well as a constructor with two parameters to initialize the room number and the room’s daily rate. The class should have get/set functions for all its private data members. The constructors and the get/set functions must throw a RunTimeException if either one of the parameter values are negative. The exception handler should display the message “Negative Parameter”. Include a toString() function that formats and returns a string that displays the information about the HotelRoom object.

A. Write a main function to test the class HotelRoom, create a HotelRoom object. Try to set the room rate to an invalid value to generate an exception. Invoke the toSting() function to display the HotelRoom object.

B. Derive the classes GuestRoom from the class HotelRoom. The GuestRoom has private data fields and public functions:

a. The private data field capacity (int) that represents the maximum number of guests that can occupy the room.

b. The private data member status (int), which represents the number of guests in the room (0 if unoccupied).

c. A data field days (int) that represents the number of days the guests occupies the room.

d. Add constructors and get/set functions to the GuestRoom class. The set function for the status data member must throw an Exception object if the function tries to set status to value greater than the capacity.

e. The function calculateBill() that returns the amount of guest’s bill.

f. Redefine the function toString() that formats and returns a string containing all pertinent information about the GuestRoom.

C. Derive the classes MeetingRoom form the base class HotelRoom. The class has the following private data fields and public functions:

a. A private data field seats, which represents the number of seats in the room.

b. An integer data field status (1 if the room is booked and 0 otherwise).

c. Add constructors and get/set functions to the GuestRoom class.

d. Redefine the function toString() to format and return a string containing all pertinent information about the MeetingRoom.

e. The function CalculateBill(), which returns the amount of the bill for renting the room for one day. The function calculates the bill as follows: the number of seats multiplied by 10.00, plus the room rate.

D. Write a main function to test the classes GuestRoom and MeetingRoom. Invoke the calculateBill() and toStirng() in each of the objects.

E. Demonstrate polymorphic behaviors. Clearly indicate how the polymorphic behavior is demonstrated through coding and output.

F. Demonstrate down-casting. Describe how down casting is demonstrated.

Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution