Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Design a class called Room in a file called Room.java. This class will hold four instance variables, one constructor, and seven methods. Create four instance

  1. Design a class called Room in a file called Room.java. This class will hold four instance variables, one constructor, and seven methods.
    1. Create four instance variables for your class (roomNumber, daysRented, roomType, and occupantName). The descriptions of these variables are provided below.
      1. The roomNumber variable is an integer. It holds the room number for this room.
      2. The daysRented variable is an integer. It holds the number of days remaining in this room rental.
      3. The roomType variable is a String. It holds one of three room descriptions: single king, double queen, suite.
      4. The occupantName variable is a String. It holds the name of the person renting this room, or null if it is unoccupied.
    2. Write a constructor method for the Room class. The constructor should take four arguments, one specifying the room number, second the room type, third the daysRented and fourth for the occupantName. Assign the room number, set the number of days rented to zero, and the occupant name to null. For the room type, check to make sure that the String matches one of the three possible room types given above, and then assign the correct type. If the type is not one of the ones given, assign the room the type double queen.
    3. Write the following methods.
      1. Write accessor methods for the four private instance variables described above. Each of these methods will return the value stored in that variable, and must be named using the expected pattern for accessor methods using the prefix get and proper camel casing.
      2. The setOccupant method takes two arguments, a String representing the name of the guest and an integer representing the number of days the guest will be staying, and returns a boolean reporting on whether or not the operation was successful. Check first to see if the Room has already been rented, and if so, simply return false. If the room is available, set the occupant name and days rented to the appropriate values and return true.
      3. The advanceDay method takes no arguments and returns no values. Reduce the number of days left in the rental by one. If the days left in the rental is zero (or less), set the occupant to null and the days left in the rental to zero.
      4. The toString method should take no arguments and return a String representing the current state of the Room instance. The format is shown below. "Room 305: single king rented" "Room 111: double queen free"
  2. Design a class called Hotel in a file called Hotel.java. This class will hold three instance variables, one constructor, and six methods.
    1. Create three instance variables for your class (hotelName, rooms, totalRooms). The descriptions of these variables are provided below.
      1. The hotelName variable is a String. It holds the name of this hotel.
      2. The rooms variable is an array of Room objects. It holds the set of rooms for the given Hotel object.
      3. The totalRooms variable is an integer. It holds the total number of rooms in the current Hotel instance.
    2. Write a constructor method for the Hotel class. The constructor should take two arguments, one specifying the hotel name and one specifying the number of total rooms. The rules for each room are as follows:
      1. The room number will be a value between 10 and 30. The first digit will correspond to what floor the room is on.
      2. The hotel has 11 double queen rooms, 5 single king rooms, and 4 suites.
    3. Write the following methods:
      1. Write three accessor methods. One accessor should simply return the number of total rooms and should follow the naming convention for accessor methods. The other two accessor methods are described below:
        1. The getNumberOccupied method should cycle through all rooms in the Hotel and count how many rooms are currently occupied. The count should be returned.
        2. The getOccupancyRate method should return a double value between 0 and 1 representing the percentage of rooms that are currently rented (we will represent 95% as 0.95). This value should always contain 2 decimal places maximum, and should be rounded using traditional rounding rules.
      2. The rentRoom method takes three arguments, the type of room, the name of the renter, and the number of days of the renters stay, and returns a boolean value indicating whether the rental was successful or not. Start at the first room in the Hotel and find the first unoccupied room that fits the renters specified room type. Set the occupant information for the first room found, and return true. If no rooms match the specification, return false.
      3. The advanceDay method should check every rented room and reduce the number ofdays left in the rental. This method must make use of the proper mutator available in theRoom class. It will not return anything.
      4. The toString method takes no arguments and returns a String representing the stateof the Hotel instance. The format is shown below. "The Queen College Union Hotel: 12% occupied".
  3. Write a test class to test all the constructors and methods of both classes.

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

The Manga Guide To Databases

Authors: Mana Takahashi, Shoko Azuma, Co Ltd Trend

1st Edition

1593271905, 978-1593271909

More Books

Students also viewed these Databases questions

Question

Identify the four elements of negligence.

Answered: 1 week ago

Question

Describe the components of a workplace wellness programme

Answered: 1 week ago

Question

What is meant by decentralisation of authority ?

Answered: 1 week ago

Question

Briefly explain the qualities of an able supervisor

Answered: 1 week ago

Question

Define policy making?

Answered: 1 week ago

Question

Define co-ordination?

Answered: 1 week ago

Question

What are the role of supervisors ?

Answered: 1 week ago

Question

Question Can a Roth IRA invest in stock of the IRA owners business?

Answered: 1 week ago