Assignment Specification

You have completed the console program for processing bookings at the Rocky Budget Hotel. We are going to extend this application so the customer's name and days to stay at the hotel can be stored in an array of objects, do not use ArrayList.

The program will run via a menu of options, the file Hotel.java has been supplied (via the Moodle web site) which supplies the basic functionality of the menu system. see image.

Look at the code supplied and trace the execution and you will see the menu is linked to blank methods (stubs) which you will implement the various choices in the menu.

Booking class

First step is to create a class called Booking (Booking.java).

The Booking class will be very simple it will contain two private instance variables:

  • name as a String
  • days as an integer

You should also have constants for the varying daily rates i.e $110, $100, $90 and $70.

The following public methods will have to be implemented:

  • A default constructor
  • A parameterised constructor
  • Two set methods (mutators)
  • Two get methods (accessors)
  • A method calculateCharges() to calculate and return the total charge. This calculation will be the same as in assignment one i.e. First day is $110, the next two days will be $100 per day, the next four days will be $90 per day and the following week will be $70 per day with a maximum of 14 days in total.

Note: following basic database principles, calculated values are not usually stored, so in this case we will not store the charges as a instance variable, but use the calculateCharges() method when we want to access the charges.

Hotel class

Once the Booking class is implemented and fully tested we can now start to implement the functionality of the menu system Hotel.java.

Data structures

For this assignment we are going to store the customer names and days to stay in an array of Booking objects.

Declare an array of Booking objects as an instance variable of the Hotel class, the array should hold twenty bookings.

You will need another instance variable (integer) to keep track of the number of the bookings being entered and use this for the index into the array of Booking objects.

Menu options

1. Enter customer name and days to stay: enterBooking()

For assignment two we are going to use the GUI dialog showInputDialog() for our input. You will need to create the following two dialogs to receive the input from the user. You will not implement the functionality of the cancel key (need to use exceptions for this). Use Integer.parseInt() to convert the number as a string into an integer for the number of days to stay. see image.

Data validation (you can implement this after you have got the basic functionality implemented) You will need to validate the user input using a validation loop.

The customer name cannot be blank i.e. not null and the days to stay cannot be blank and days needs to be between one and fourteen (1-14) inclusive, the same as assignment one.

Output the following error dialogs: see image.

When the customer name and days to stay have been entered successfully into two local variables you will need to add these values into the Booking object array, you will also need to increment a counter to keep track of the number of bookings you have entered and the position in the array of the next booking to be entered.

When the maximum number of bookings is reached (20) do not attempt to add any more bookings and give the following error message: see image.

When the booking details have been successfully entered, display the details of the booking and the charge on the console screen. see image.

Note: For the three options, display all, statistics and search you should ensure at least one booking has been entered and give an appropriate error message if there are no bookings entered and for the sorting option you must ensure at least two bookings have been entered, for example: see image.

2. Display all bookings: displayAllBookings()

When this option is selected display all of the bookings which have been entered so far. see image.

3. Display statistics: displayStatistics()

When this option is selected you will display the statistics as per assignment one. You can loop through your array of objects to calculate this information. see image.

4. Search for booking: searchBookings()

You can just use a simple linear search which will be case insensitive. Use the showInputDialog() method to input the name (you can share this functionality from enter name in enter booking). see image.

If the search is successful display the details about the booking. see image.

If the search is unsuccessful display an appropriate message. see image.

5. Sort the bookings: sortBookings()

This option you will sort the bookings alphabetically (ignore case) by the customer names, you can use any sorting algorithm which you like, do not use any in-built sort methods. Display the sorted list after the sort is complete. see image.

Remember the welcome and exit messages as per assignment one. see image.

Extra Hints

Your program should be well laid out, commented and uses appropriate and consistent names (camel notation) for all variables, methods and objects.

Make sure you have no repeated code (even writing headings in the output)

Constants must be used for all numbers in your code.

Look at the marking criteria to ensure you have completed all of the necessary items Refer to a Java reference textbook and the unit and lecture material (available on the unit web site) for further information about the Java programming topics required to complete this assignment. Check output, check code and add all of your comments, complete report and the UML class diagram.

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.