QuestionQuestion

Simplified Airline Reservation System
The goal of this project is to create a simple simulation of a booking system for a small airline that runs commuter flights between two
cities on a daily basis. Your projects should just keep track of flights for the month of August 2017. The classes that you develop could be used to create much more complicated simulations involving multiple airlines and many cities, but for this project only a very simple simulation is required. Your project should use implementations for 5 classes called:
Main, Passenger, Ticket, Airline, Flight.

The Main class contains only static methods (and no instance variables). Its static methods are used to run the simulation and call on
the other classes as needed. This should be the last class implemented and should carry out the simulation described below. It is best to start with the other four classes. For each of the classes you should start by deciding what type to use for each of the instance variables. The next few paragraphs outline possible instance variables and methods for these classes. It is possible to implement the simulation using only these variables and methods, however you may use any other choice of variables and methods that allows you to carry out the required simulation. The class Airline contains information about all the flights for an airline. It uses instance variables name and flights. The variable flights should be an ArrayList of Flight objects. The class Passenger contains information about a passenger. It uses instance variables firstName, lastName, address, phone and myTickets. The field my Tickets is an ArrayList of tickets that is used to store all the airline tickets that have been booked by a passenger. The class Ticket contains information about a ticket. It uses instance variables ticketNumber, myAirline, myPassenger, myFlight and price. The class should also have a static data field called counter which is increased every time a new ticket is issued. This static field can be used to make sure that ticket numbers are unique (and not shared by two different tickets). The class Flight contains information about a flight. It uses in- stance variables flightNumber, seats, filledSeats, flightLength, airline, date, originAirport, destination, departure Time and tickets. The field tickets should be an ArrayList of tickets that have been issued for the flight. A static field called counter should be used to keep account of the different flights and make sure that each gets a different flight number.

For each of these four classes, there is one constructor. The parameters for this constructor should give values for instance variables. However, if the value for an instance variable can be automatically generated no corresponding parameter should be used. So for example the Flight constructor would not use a parameter to specify filledSeats since this always begins with the value o. Similarly, the constructor for a Ticket would not have a parameter to specify a ticketNumber since this is automatically generated by using the static field counter. For each instance variable in each class you should implement a getter method. For each instance variable that could be changed you should implement a setter method too. However, for instance variables like a passenger name which are never changed do not supply a setter. This ensures that passenger names can't be accidentally corrupted. For each of the four classes supply a toString method that can be used for testing purposes and can also provide useful output in the main simulation. The other methods that belong to these four classes have the following title lines and tasks.

For the class Passenger:
void cancel(Ticket t)
cancels the passenger's ticket t
ArrayList findFlights (Airline a, String date, double time, String from)
finds all flights for an airline on a particular date within 4 hours of a
particular departure time from a particular city.
Ticket bookFlight (Flight f)
books a ticket for a particular flight (for the passenger)
.
boolean holdsTicket (Ticket t)
reports where the passenger holds a particular ticket

For the class Ticket:
void cancel()
cancels the ticket

For the class Airline:
void cancel(Ticket t)
cancels a ticket
void issueRefund (Ticket t)
issues a refund --- it just prints a message about which passenger has been credited how much money since in this simulation we will not keep track of bank balances for passengers or airlines. ArrayList findFlights (String date, double time, String origin) finds all flights for a 4 hour departure window Ticket book(Passenger p, Flight f) books a passenger on a flight double cost (Flight f) gives the cost of a ticket for a particular flight. Devise you own sensible pricing policy so that tickets get more expensive as a flight fills up. Void createFlight (double time, int numSeats, String from, String to) creates a new flight for the Airline and makes sure that this flight operates every day.

For the class Flight:
boolean matches (String d, double t, String from)
Does the flight match date d, time t and originAirport from
to within a 4 hour departure window
boolean hasSpace()
Are there any empty seats left?
void addTicket (Ticket t)
Add a newly issued ticket to the flight
boolean holdsTicket (Ticket ticket)
Does the flight already hold a particular ticket?
void remove(T: ticket)
Remove a canceled ticket from the flight.
double getCost()
Use the flight's airline's method to generate the cost of the next ticket
for this flight.

For the class Main
You should create a main method that operates the following simulation.
This main method might usefully call on other static methods to carry out parts of its task.

The simulation to be carried out by the main class is as follows:
1. Create a new Airline object
2. Randomly generate flights for the airline for the month of August 2017. There should be about one flight per hour in each direction between 6am and 10pm. The same flights should operate each day of the month. Flight numbers should be the same from day to day
3. Generate 10000 random passengers each of whom books one flight.
4. Ask the user to create their passenger data.

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.

import java.util.*;

/*
* Main class for program execution
*/
public class Main {
   
public static void main(String[] args) {
   
    Scanner s = new Scanner(System.in);
   
    Airline airline = new Airline("Java Air");
   
    for (double time = 6.0; time <= 22.0; time++) {
      String from = "" + (char)(time+59) + (char)(time+59) + (char)(time+59);
      String to = "" + (char)(time+60) + (char)(time+60) + (char)(time+60);
      airline.createFlight(time, 2, from, to);
    }
   
    for (int i = 0; i < 1000; i++) {
      Passenger p = new Passenger();
      while (true) {
       int j = (int)(Math.random()*(airline.getFlights().size()));
       Flight f = airline.getFlights().get(j);
       if (f.hasSpace()) {
          p.bookFlight(f);
          break;
       }
      }
    }
   
    Passenger p = new Passenger();
   
    System.out.println("=== Passenger Data ===");
    System.out.print("Enter first name: ");
    p.setFirstName(s.nextLine());...

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

$60.00
for this solution

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

Find A Tutor

View available Computer Science - Other 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