CIS 35A: Introduction to Java Programming

Home | Green Sheet | Lectures | Assignments | FAQ | Grades | Students

Assignment #11

Calculate reservation totals

Due Date: Monday of Week 5
20 points

This project requires creating GregorianCalendar objects from the values the user enters, creating Date objects from the GregorianCalendar objects, and calculating the days between two dates. It also requires the use of the DateFormat class to format the dates that are displayed at the console. This is a good project for working with dates that's not too complicated.

Console

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.

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.
  • Allow the user to enter the room rate or select the rate from one of several available rates.
  • Use the BigDecimal class rather than the double type for the price calculation.
Include in your program the following comments:
  • Name of program
  • Programmer's name
  • Current Date
  • Computer system and compiler you are using
  • Brief description of the program

Compile and run the Java program.

When you are ready, upload the java program by clicking the link below:

Upload Assignment

I cannot grade if I don't get the files and receive your email.