QuestionQuestion

Design

For this project, you will need to design and implement the following classes (at a minimum):

Reservation Class:
• The class should store the first name, last name, flight price, seat number and seat letter.
The class should provide the following methods, at a minimum:
• print: Returns a String that contains the information in the reservation
• getPrice: Returns the price of the reservation

ReservationSystem Class:
• The class should store an ArrayList of Reservations.
The class should provide the following methods:
• addReservation: Takes as input last name, first name, price, seat number and seat letter and creates a Reservation with this information. Add the reservation to the list of reservations.
• addReservation: Prompts the user for the info needed to make a new reservation. Add the reservation to the list of reservations.
• findReservation: find a reservation by first and last name and returns it
• viewReservations: prints all reservations using System.out. Use the print method provided by
Reservation
• uploadReservations: asks the user for a file and reads in all the reservations from a file and saves them in the ArrayList. Uses the addReservation method for help.
• downloadReservations: takes a file as input and writes the reservations to the file. Use the
print method provided by Reservation
• updateReservation: asks the user for the first and last name of the reservation to update and then asks for the data to be updated and updates the reservation.
• getTotalPrice: Calls getPrice on each individual Reservation and adds them all up

Documentation:
All methods implemented should have javadoc comments written for them.

Program Input:
Your program will display a welcome message to the user and a menu of options for the user to choose from.

After completing a task, the main menu will be displayed again.

Program Options
Option 1: Upload Reservations
If the user chooses this option, the program will
a. Prompt the user for the file that contains the reservations.
b. Read in the records into the ReservationSystem.

Input File Format:

LastName FirstName Price SeatNumber SeatLetter Sample Input File:
Bob Mike 200 23 B
Matt Benjamin 178 15 A
Keller Helen 135.99 6 D
Tim Mary 210.77 12 B

Use the uploadReservations method to upload the reservations to the ReservationSystem.

Option 2: New Reservation
This option will prompt the user for the information needed to make 1 reservation and store it in the
ReservationSystem.
You need to make sure that the seat number is between 1-30. You need to make sure the seat letter is either A, B, C, D or E.

Option 3: Update Reservation
When this option is selected, the program will ask for the first and last name of the reservation and prompt the user for the seat number and seat letter. Use the updateReservation method for this task.

Option 4: View All Existing Reservations
If the user chooses this option, the program will print to the screen all the reservations’ information. Use the viewReservations method for this task.

Sample Output:
Name: Mike Bob, Price: 200, Seat: 23B Name: Benjamin Matt, Price: 178, Seat: 15A Name: Helen Keller, Price: 135.99, Seat: 6D Name: Mary Tim, Price: 210.77, Seat: 12B

Option 5: Find Reservation
If the user chooses this option, the program will prompt the user for their first and last name and search for a reservation with that first and last name combination and display it to the screen. If no reservation is found, a message will be displayed indicating that. Use the findReservation method for this task.

Option 6: Download Statistics
If the user chooses this option, the program will create a statistics file with the following data:
a. Printout of all reservations – use the downloadReservations method for this task
b. Sorted customer names alphabetically (by last name)
c. Lowest flight price
d. Highest flight price
e. Total cost of reservations – use the getTotalPrice method in the ReservationSystem
class

The statistics file will have the same name as the input file (from option 1) but with _stats.txt
appended to it.
For example, if the input file was named reservations.txt, the stats file will be named
reservations_stats.txt.

Note: It will remove the .txt from reservations.txt, before adding the _stats.txt. It will NOT create a file with the name reservations.txt_stats.txt. You can use the string substr method to remove the last 4 characters from the file name.

Write a static function called CreateStatsFile to do this task. Choose the appropriate parameters and return type.

Option 5: Exit the Program
If the user chooses this option, the program will exit.
Note: If any other option (other than exit) is chosen, the task will be performed and then the menu will be displayed again.

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

public class ReservationSystem {

private ArrayList<Reservation> reservations;
private static String inputFile;

// Constructor
public ReservationSystem() {
    reservations = new ArrayList<Reservation>();
}

// Method to add Reservation with parameters
public void addReservation(String lastName, String firstName, double price, int seatNumber, char seatLetter) {
    reservations.add(new Reservation(lastName, firstName, price, seatNumber, seatLetter));
}

// Method to add Reservation with user input
public void addReservation(Scanner s) {
    System.out.print("Enter first name: ");
    String firstName = s.nextLine();
    System.out.print("Enter last name: ");
    String lastName = s.nextLine();
    System.out.print("Enter price: ");
    double price = Double.parseDouble(s.nextLine());
    System.out.print("Enter seat number: ");
    int seatNumber = Integer.parseInt(s.nextLine());
    System.out.print("Enter seat letter: ");
    char seatLetter = s.nextLine().charAt(0);
    addReservation(lastName, firstName, price, seatNumber, seatLetter);
}

// Method to find Reservation
public Reservation findReservation(String firstName, String lastName) {
    for (Reservation reservation: reservations) {
      if (reservation.getFirstName().equals(firstName) && reservation.getLastName().equals(lastName))
       return reservation;
    }
    return null;
}

// Method to view Reservations
public void viewReservations() {
    for (Reservation reservation: reservations) {
      System.out.println(reservation.print());
    }
}

// Method to upload Reservations
public void uploadReservations(Scanner s) {
    System.out.print("Enter file: ");
    String file = s.nextLine();
    inputFile = file;
    try(BufferedReader br = new BufferedReader(new FileReader(file))) {
      for(String line; (line = br.readLine()) != null; ) {
       String[] params = line.split("\\s+");
       String lastName = params[0];
       String firstName = params[1];
       double price = Double.parseDouble(params[2]);
       int seatNumber = Integer.parseInt(params[3]);
       char seatLetter = params[4].charAt(0);
       addReservation(lastName, firstName, price, seatNumber, seatLetter);
      }
    } catch (IOException e) {
      e.printStackTrace();
    }
}...

By purchasing this solution you'll be able to access the following files:
Solution.zip.

$54.00
for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Java Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats