Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

***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).

***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 rooms 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 guests 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.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases Illuminated

Authors: Catherine Ricardo

2nd Edition

1449606008, 978-1449606008

More Books

Students also viewed these Databases questions