Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Help with Java please: Develop a simple Hotel program. We will have two classes, a Hotel class representing an individual hotel and a Room class.

Help with Java please:

  1. Develop a simple Hotel program. We will have two classes, a Hotel class representing an individual hotel and a Room class. The Hotel class will contain several Room objects and will have several operations. We will also have a driver program to test the Hotel class.
  2. Build a Hotel class that will store information about a Hotel. It will include a name and location. It should also include an Array of instances of class Room to hold information about each room. This Array of Room objects may be a partially filled array, thus it must also have an integer to track how many rooms are in the hotel.
  3. The program must use a standard Java Array. The Array should be able to hold up to 10 Room objects.
  4. Build a HotelTest class to test your application.
    1. Your test class should not require any interaction with the user.
    2. It should verify the correct operation of the constructor and all public methods in the Hotel class.
    3. Create at least 5 Rooms in the Hotel.
    4. Display output info for the hotel - should roughly match what is given below under Sample Hotel Output. This should be done by using the toString methods you create.
    5. "Book" several rooms, that is, set it's status to occupied.
      1. Be sure to test unsuccessful bookings as well, no matching room exists, or matching room is occupied.
    6. Verify that the hotel info has been updated.
    7. Be sure that you are testing all of the methods in both the Hotel and Room class. This can include indirect testing where a method is called by another method that does get tested directly.
  1. Create a project that is object oriented, therefore there should be several classes.
  2. The class you use to test your Hotel and Room classes is not included in the UML below.

image text in transcribed

Room

  1. Instance Variables
    1. roomNumber: int - number of the room
    2. bedType: String - type of bed(ie king, queen etc)
    3. rate: int - cost of the room
    4. occupantName: String - name of occupant, or the empty String ("") if not occupied
  2. Constructors
    1. Default constructor sets all instance variables to a default value
    2. Parameterized Constructor
      1. Takes in room number, bed type, and room rate, as parameters and sets the appropriate instance variable to those values
      2. Sets the occupants name to the empty String ("");
  3. Methods
    1. isOccupied - method returns true if the room is occupied, false otherwise.
    2. toString
      1. Provides all the details of a room - room number, name of guest (if occupied), bed type, and rental rate in a nicely formatted manner such as that given in Sample Room Output below.
      2. One attribute on each line is preferred.

Sample Room Output:

Room Number: 101 Occupant name: Not Occupied Bed Type: queen Rate: 100 

Hotel

  1. Instance Variables
    1. rooms: An Array of Room Objects
    2. name: String - hotel name
    3. location: String - hotel location
    4. numberOfRooms: int number of rooms in the hotel.
    5. private static final int NOT_FOUND = -1;: this is similar to a constant in other languages and is used here to indicate that a search was unsuccessful.
  2. Constructors
    1. Should use mutator methods to set all instance variable.
    2. A default constructors that sets the Array to a size of 10 and all instance fields to a default value.
    3. Parameterized constructor
      1. Takes in parameters for name and location and sets those instance variables to the parameter values.
      2. Assigns numberOfRooms to zero. numberOfRooms indicates how many rooms are in the hotel. It will create a 10 element array.
  3. Methods
    1. isFull - returns a boolean that is true if all the rooms in the hotel are occupied.
    2. addRoom - returns true if room is added, false if not.
      1. Takes 3 arguments: the room number, bed type, and room rate.
      2. If numberOfRooms is less than the capacity of rooms:
        1. Create a Room object from the parameters list.
        2. Adds the Room object to rooms.
        3. Increments numberOfRooms (indicates how many actual rooms are in the hotel).
        4. Returns true.
      3. Otherwise, returns false since no more rooms can be added.
    3. addReservation
      1. Takes two arguments: the occupant's name and the requested bed type.
      2. Searches the array of rooms for one that matches the bed type. Remember to use the partially filled array value numberOfRooms in your search loop.
      3. If an unoccupied room with the correct attributes is found, the occupant's name will be set and the occupied attribute will be set to true. In either case a message will be printed that will state whether or not the reservation was made.
    4. findReservation
      1. Private method - only accessible from other method sn the class.
      2. Takes a String arguments representing the occupant's name.
      3. Searches the occupied rooms for a reservation with that occupant name.
      4. Returns the index of the room or NOT_FOUND if not found.
    5. cancelReservation
      1. Takes in a string representing the name of a guest.
      2. If a room is found to be occupied by the specified guest, update the occupantName and isOccupied values for the room. If multiple rooms exist with the same occupant, you are free to either clear only the first match, or all.
      3. In either case, output a message stating whether or not the reservation was cancelled.
      4. This method should utilize the private utility method findReservation() to scan the list of rooms looking for a room by guest name.
      5. The findReservation method will return the index of the room in the Array of rooms or NOT_FOUND if the room is not found.
    6. toString
      1. Returns a nicely formatted string giving hotel and room details.
      2. Calls the Room class's toString method.

Sample Hotel Output:

Hotel Name: Beach Marriot Location: Pensacola Number of Rooms : 5 Current revenue: $198 =========================== Room Number: 101 Occupant name: Not Occupied Bed Type: queen Rate: 100 Room Number: 102 Occupant name: Popeye Bed Type: king Rate: 110 Room Number: 103 Occupant name: Donald Duck Bed Type: king Rate: 88 Room Number: 104 Occupant name: Not Occupied Bed Type: twin Rate: 100 Room Number: 105 Occupant name: Not Occupied Bed Type: queen Rate: 99

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions