Calculate reservation totals

Console

Welcome to the Reservation Calculator.

Enter the arrival month (1-12): 5
Enter the arrival day (1-31): 16
Enter the arrival year: 2005

Enter the departure month (1-12): 5
Enter the departure day (1-31): 18
Enter the departure year: 2005

Arrival Date: Monday, May 16, 2005
Departure Date: Wednesday, May 18, 2005
Price: $115.00 per night
Total price: $230.00 for 2 nights

Another reservation? (y/n): n

Operation

  • This application calculates the charges for a stay at a hotel based on the arrival and departure dates.
  • The application begins by prompting the user for the month, day, and year of the arrival and the departure.
  • Next, the application displays the arrival date, the departure date, the room rate, the total price, and the number of nights.

Specifications

  • Create a class named Reservation that defines a reservation. This class should contain instance variables for the arrival date and departure date. It should also contain a constant initialized to the nightly rate of $115.00.
  • The Reservation class should contain a constructor that accepts the arrival and departure dates as parameters of type Date, as well as methods that return the number of nights for the stay (calculated by subtracting the arrival date from the departure date) and the total price (calculated by multiplying the number of nights for the stay by the nightly room rate). This class should also override the toString method to return a string like this:
Arrival Date: Monday, May 16, 2005
Departure Date: Wednesday, May 18, 2005
Price: $115.00 per night
Total price: $230.00 for 2 nights
  • The main method for the application class should contain a loop that asks the user for the arrival and departure date information, creates a Reservation object, and displays the string returned by the toString method.
  • Assume valid data is entered.

Required Enhancements

  • Add validation so the user must enter values that will result in a correct date.
  • Allow the user to enter the date in the form mm/dd/yyyy.

Note

  • This application requires the use of the GregorianCalendar class to create dates from the int values entered by the user. Then, it requires the use of the getTime method to convert the GregorianCalendar object to a Date object.
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.