Your task this week is to implement a simple hotel reservation system. This system will allow customers to request any available room, request a specific room, and cancel reservations.
Since the staff is optimistic about future economic growth the reservation system also has to accomodate the growth of the hotel. In other words, the proprieter should be able to add additional rooms without disturbing exisitng reservations.
The Reservation class
The Reservation class is a simple class that models customer reservations, including the customer's name and the room number. As you might expect, the Reservation class provides some simple methods for maintaining an individual reservation.
Please consult the comments in the class skeleton for the details of each method's paramters and behaviors. Please also note that you may or may not actually use all of the methods of this class in your implementation of the reservation system, but should implement and test them, anyway.
The Hotel class
The Hotel class models the hotel as a collection of rooms, each of which is represented as a Reservation, either actual, or null.
To maintain the Reservations associated with each room, the Hotel class will contain a ArrayList. If you don't remember ArrayLists from your prior course, please don't worry. They are a very simple indexed collection, much like an Array. They have a much richer collection of behaviors. Among their additional capabilities is their ability to grow on the fly.
Be sure to familiarize yourself with the ArrayList API before beginning. Please pay close attention to the difference between the size() and capacity() methods.
You will need to complete the following methods of the Hotel class. For more detail, please see the comments within the skeleton.
- public int reserveRoom(String person)
This method should instantiate a Reservation and insert it into a empty room. This function should then return the room number. In the case where the hotel is full, you should return -1.
- public boolean reserveRoom(String person, int roomNum)
This method reserves the specified room for the customer if possible. It returns true on success, or false if the room could not be reserved.
- public void cancelReservations(String person)
This method cancels all the reservations for the specified customer.
- public void printReservations()
This method prints out all current reservations. Also, you should print how many reservations and free rooms there are.
The Simulation Class
This class contains the main() method for the simulation. It creates a new Hotel and provides a menu system and work loop that yield a very simple reservation system. If you give careful thought to your test cases, this system will allow you to test your implementation of the other classes.
As before, more detail is provided by the comments within the Simulation class. But, this time you should not be concerned with every detail. For example, we don't expect that you'll remember how Java I/O works. At this point, it is okay if you just accept that this piece of the code works as intended.