Project 5

Come Fly With Me

Due: Monday, April 23, 8 AM
Submit Project: Proj5
Required Files: Proj5.java, Airport.java, Airplane.java, Seat.java,
Input File: airplanes.txt
Grading Header: header.txt
Test data: testa.dat
Model Output: out.dat

Again we move to more new concepts to incorporate into a new project - arrays, classes, files and exceptions (though I've written the code that incorporates these last two items) . This project continues to feature elements from prior projects including loops and supporting classes. The main program should be in Proj5.java (which I have given to you) and the supporting classes are Airport.java, Airplane.java, and Seat.java. This project attempts to bring together everything we've learned up to this point into one big (read many key strokes) project, so plan accordingly.


Program Description

You are required to write a program to handle the planes and the reservations for flights out of an airport. The information about flights from the airport is kept in an external file called airplanes.txt. The organization of the classes is as follows. There are seats (Seat.java) which contain 3 instance variables: the String occupant, a character for the class of the seat (First class or Economy) and a character for if the class is smoking (S) or non-smoking (N). Each plane (Airplane.java) is made up of a 2-dimensional array of seats. Also each plane (flight) has a flight number, a destination, the number of rows, the number of seats/row, the number of first class rows, and the number of non-smoking rows. The airport (Airport.java) is then made up of a 1-dimensional array of airplanes. In addition there is a count of how many planes are at the airport and a constant for the name of the airport. Your program must first read the flight information into the array of planes (I've written this code for you). Proj5.java will continually print a menu of options which include printing a list of flights, getting information about a flight, booking passengers on a particular flight, printing an occupancy chart for a flight and printing a manifest of passengers for a flight, as well as quit.

Now working from the inside out, these are the classes you will need:

Seat.java
This class contains methods needed to handle information about a seat. There are three instance variables: occupant, whichClass, and smoking. The methods you must implement include:

  • constructor - This method accepts two char arguments: whichClass and smoke. These should be assigned to the appropriate instance variables. Leave occupant empty until someone books that seat explicitly.
  • getOccupant(), getWhichClass(), and getSmoking() - Accessor methods
  • setOccupant(), setClass(), and setSmoking() - Mutator methods
  • equals() - determines if two seats have the same occupant
  • isEmpty() - returns true if the seat has no occupant.
  • toString() - This method returns a String containing the class of the seat, whether it's a smoking or non-smoking seat, and the occupant if there is one.

    Airplane.java
    This class is the workhorse for this project. There are 7 instance variables: a 2-dimensional array of seats (un-instantiated), the flight number of the flight, the destination, the number of rows and seats/row, the number of first class rows, and the number of non-smoking rows. The methods should include but are not limited to:

  • a constructor which takes in a flight number, destination, number of rows, number of seats/row, number of first class rows and number of non-smoking rows. The instance variables should be initialized with these values. In addition, you should instantiate a plane with the number of rows and seats per row as the array size parameters. Then each seat must be instantiated. You should run a loop for all the first class rows setting the type to F and the smoking variable to N. Then you should run a loop for all the economy class rows that are non-smoking, setting the type to E and the smoking variable to N. Then a final loop should set the rest of the rows to E and S.
  • getFlightNumber(), getDestination(), getRows(), getSeats(), getFirstClassRows(), getNonSmokingRows() - accessor methods.
  • getInformation() - returns a String that lists all information about a flight.
  • setFirstClassRows() - resets the number of first class rows. Make sure all these seats are non-smoking.
  • setOccupant() - put a person into a seat
  • setNonSmoking() - resets the number of non-smoking rows. Make sure that the first-class seats, if any, remain non-smoking.
  • setDestination(), setFlightNumber() - other mutator methods. (Note the number of rows and seats/row can not change.
  • toString() - this returns a String of information about the flight including its flight number and destination.
  • printOccupancyChart() - this prints a chart of the plane and all the seats. If the seat is occupied, it prints an X for that seat. If it's not occupied, it prints the 2-character combination of the class and the smoking status of the seat.
  • print Manifest() - this prints a list of the seat numbers and occupants of only the occupied seats.
  • addPassengers() - This method allows the entry of a passenger's name, what class they'd like, if it's economy whether smoking or non-smoking, the desired row and seat, and tests to see if that all makes sense (is the seat not occupied and is the row and seat requested the proper class and smoking seat on the plane) (these should be calls to two boolean private methods to see if the seat is available and appropriate). If all is appropriate, book the passenger in the seat and print an appropriate message. If it is not appropriate, ask the user if he/she wants to reenter the data or exit this routine. If R then loop back and reenter the data and try again. If E then exit this routine and book no one at this time.
  • available() - determines if the seat if available
  • appropriate() - determines if the seat fits the customer's criteria

    Airport.java
    This class contains an array of planes and a count of how many there are as instance variables. I've also included a String with the airport name as a public constant. Some of the methods needed are:

  • readAirplanes() - This method reads flight information into the array of flights from an external file called airplanes.txt. I have written this method for you. You should study it and understand how it works. There is a try/catch block to make sure the file is there. Also there is information about getting input from an external file. It prints a count of how many flights have been read in. After this method runs, the airport list will have the flight information in it.
  • toString() - This should return a String containing a list of the flight numbers and destinations (call Airplane's toString() in a loop).
  • getInfo() - takes in a flightNumber and returns a string with all the information about that flight. If the flight is not at the airport, an error message should print.
  • manifest() - This takes in a flightNumber and should return a String that contains a list of all the passengers on this flight (should call Airplane's printManifest()). It must first find the flight in the list. If it's not there an error message should print.
  • occupancyChart() - This takes in a flightNumber and calls Airplane's printOccupancyChart() to print the grid of seat information about this flight. If the flight does not exist, an error message should print.
  • addPassengers() - This takes in a flightNumber and the Scanner and if the flight exists it should call upon Airplane's addPassengers.
  • search() - this is a private method that I created since so many of the above routines need to find a particular flight in the list. It takes in a flight number and returns the index in the array if the flight exists. If the flight doesn't exist, a -1 is returned.

    Proj5.java

    This is the driver program which starts by declaring the Airport variable. The method to read in the flight information should be called. Then in a do/while loop print the following menu, allow the user to enter a choice, if the choice is not a Q or a L then it should request a flight number, and then in a switch statement, it should execute that choice. The menu should look something like:

    -----------------------------------------
    
    *** Main Airport Menu ***
    
    L) List the flight numbers
    I) Get Airplane flight inforamtion
    A) Add passengers to a flight
    O) Print occupancy chart for a flight
    M) Print a manifest for a flight
    Q) Quit
    
    Please enter choice->
    
    
    If 'L' is chosen, print out the airport information - the list of flights.

    If 'I' is chosen, print out information about a particular flight

    If 'A' is chosen, you should call the addPassengers method in Airport passing it the flight number. If the flight exists, call Airplane's addPassengers method to get the passenger information and book the passenger on the flight.

    If 'O' is chosen, the program should print an occupancy chart for this particular flight number if it exists.

    If 'M' is chosen, the program should print a flight manifest for the particular flight number if it exists.

    If 'Q' is chosen the program should quit with a Thank You message.

    Be sure your switch statement handles an incorrect choice.


    Project Specifications

  • The project should be coded in four classes called: Proj5.java, Airport.java, Airplane.java,and Seat.java.

  • Don't forget to echo-print all keyboard input.


    Sample run from keyboard

    
    6 flights read.
    
    
    ***  Main Aiport Menu ***
    
    L) List the flight numbers.
    I) Get Airplane flight information.
    A) Add passengers to a flight.
    O) Print Occupancy Chart for a flight.
    M) Print Manifest for a flight.
    Q) Quit.
    
    
    Enter choice -> l
    l
    
    William and Mary Regional Airport
    
    UA312          Dinnehotso
    Delta222       Kayente
    USAir413       Cleveland
    TA414          Atlanta
    UA110          New York
    PanAm15        Chinle
    
    
    
    ***  Main Aiport Menu ***
    
    L) List the flight numbers.
    I) Get Airplane flight information.
    A) Add passengers to a flight.
    O) Print Occupancy Chart for a flight.
    M) Print Manifest for a flight.
    Q) Quit.
    
    
    Enter choice -> i
    i
    Enter the flight number -> UA312
    UA312
    
    Information on flight UA312
    Destination:            Dinnehotso
    Number of rows:         13
    Number of seats across: 6
    Rows in First Class:    2
    Non-smoking rows:       7
    
    
    ***  Main Aiport Menu ***
    
    L) List the flight numbers.
    I) Get Airplane flight information.
    A) Add passengers to a flight.
    O) Print Occupancy Chart for a flight.
    M) Print Manifest for a flight.
    Q) Quit.
    
    
    Enter choice -> o
    o
    Enter the flight number -> UA312
    UA312
    
    
    Flight UA312 to Dinnehotso
            A  B  C  D  E  F
    Row 1   FN FN FN FN FN FN
    Row 2   FN FN FN FN FN FN
    Row 3   EN EN EN EN EN EN
    Row 4   EN EN EN EN EN EN
    Row 5   EN EN EN EN EN EN
    Row 6   EN EN EN EN EN EN
    Row 7   EN EN EN EN EN EN
    Row 8   ES ES ES ES ES ES
    Row 9   ES ES ES ES ES ES
    Row 10  ES ES ES ES ES ES
    Row 11  ES ES ES ES ES ES
    Row 12  ES ES ES ES ES ES
    Row 13  ES ES ES ES ES ES
    
    
    ***  Main Aiport Menu ***
    
    L) List the flight numbers.
    I) Get Airplane flight information.
    A) Add passengers to a flight.
    O) Print Occupancy Chart for a flight.
    M) Print Manifest for a flight.
    Q) Quit.
    
    
    Enter choice -> a
    a
    Enter the flight number -> UA312
    UA312
    Enter the name of the new passenger-> Fred Flintstone
    Fred Flintstone
    Enter the ticket type (E or F)-> e
    E
    Enter smoking or non (S or N)-> s
    S
    Enter desired row-> 9
    9
    Enter desired seat-> a
    A
    Fred Flintstone seated on flight UA312 in seat 9A
    
    
    ***  Main Aiport Menu ***
    
    L) List the flight numbers.
    I) Get Airplane flight information.
    A) Add passengers to a flight.
    O) Print Occupancy Chart for a flight.
    M) Print Manifest for a flight.
    Q) Quit.
    
    
    Enter choice -> a
    a
    Enter the flight number -> UA312
    UA312
    Enter the name of the new passenger-> Barney Rubble
    Barney Rubble
    Enter the ticket type (E or F)-> f
    F
    Enter desired row-> 1
    1
    Enter desired seat-> c
    C
    Barney Rubble seated on flight UA312 in seat 1C
    
    
    ***  Main Aiport Menu ***
    
    L) List the flight numbers.
    I) Get Airplane flight information.
    A) Add passengers to a flight.
    O) Print Occupancy Chart for a flight.
    M) Print Manifest for a flight.
    Q) Quit.
    
    
    Enter choice -> a
    a
    Enter the flight number -> UA312
    UA312
    Enter the name of the new passenger-> Sam Spade
    Sam Spade
    Enter the ticket type (E or F)-> e
    E
    Enter smoking or non (S or N)-> n
    N
    Enter desired row-> 6
    6
    Enter desired seat-> f
    F
    Sam Spade seated on flight UA312 in seat 6F
    
    
    ***  Main Aiport Menu ***
    
    L) List the flight numbers.
    I) Get Airplane flight information.
    A) Add passengers to a flight.
    O) Print Occupancy Chart for a flight.
    M) Print Manifest for a flight.
    Q) Quit.
    
    
    Enter choice -> m
    m
    Enter the flight number -> UA312
    UA312
    
    Manifest for flight UA312 to Dinnehotso
    1C   Barney Rubble
    6F   Sam Spade
    9A   Fred Flintstone
    
    
    ***  Main Aiport Menu ***
    
    L) List the flight numbers.
    I) Get Airplane flight information.
    A) Add passengers to a flight.
    O) Print Occupancy Chart for a flight.
    M) Print Manifest for a flight.
    Q) Quit.
    
    
    Enter choice -> a
    a
    Enter the flight number -> UA312
    UA312
    Enter the name of the new passenger-> George Jetson
    George Jetson
    Enter the ticket type (E or F)-> f
    F
    Enter desired row-> 2
    2
    Enter desired seat-> a
    A
    George Jetson seated on flight UA312 in seat 2A
    
    
    ***  Main Aiport Menu ***
    
    L) List the flight numbers.
    I) Get Airplane flight information.
    A) Add passengers to a flight.
    O) Print Occupancy Chart for a flight.
    M) Print Manifest for a flight.
    Q) Quit.
    
    
    Enter choice -> a
    a
    Enter the flight number -> UA312
    UA312
    Enter the name of the new passenger-> bad guy
    bad guy
    Enter the ticket type (E or F)-> e
    E
    Enter smoking or non (S or N)-> n
    N
    Enter desired row-> 2
    2
    Enter desired seat-> b
    B
    This seat is not available or does not fit the passenger's criteria or is not a valid seat.
    Would you like to reenter data (R) or Exit(E)-> r
    r
    Enter the ticket type (E or F)-> e
    E
    Enter smoking or non (S or N)-> n
    N
    Enter desired row-> 10
    10
    Enter desired seat-> c
    C
    This seat is not available or does not fit the passenger's criteria or is not a valid seat.
    Would you like to reenter data (R) or Exit(E)-> r
    r
    Enter the ticket type (E or F)-> e
    E
    Enter smoking or non (S or N)-> s
    S
    Enter desired row-> 10
    10
    Enter desired seat-> c
    C
    bad guy seated on flight UA312 in seat 10C
    
    
    ***  Main Aiport Menu ***
    
    L) List the flight numbers.
    I) Get Airplane flight information.
    A) Add passengers to a flight.
    O) Print Occupancy Chart for a flight.
    M) Print Manifest for a flight.
    Q) Quit.
    
    
    Enter choice -> o
    o
    Enter the flight number -> UA312
    UA312
    
    
    Flight UA312 to Dinnehotso
            A  B  C  D  E  F
    Row 1   FN FN X  FN FN FN
    Row 2   X  FN FN FN FN FN
    Row 3   EN EN EN EN EN EN
    Row 4   EN EN EN EN EN EN
    Row 5   EN EN EN EN EN EN
    Row 6   EN EN EN EN EN X
    Row 7   EN EN EN EN EN EN
    Row 8   ES ES ES ES ES ES
    Row 9   X  ES ES ES ES ES
    Row 10  ES ES X  ES ES ES
    Row 11  ES ES ES ES ES ES
    Row 12  ES ES ES ES ES ES
    Row 13  ES ES ES ES ES ES
    
    
    ***  Main Aiport Menu ***
    
    L) List the flight numbers.
    I) Get Airplane flight information.
    A) Add passengers to a flight.
    O) Print Occupancy Chart for a flight.
    M) Print Manifest for a flight.
    Q) Quit.
    
    
    Enter choice -> a
    a
    Enter the flight number -> UA312
    UA312
    Enter the name of the new passenger-> Joe Bloe
    Joe Bloe
    Enter the ticket type (E or F)-> f
    F
    Enter desired row-> 2
    2
    Enter desired seat-> a
    A
    This seat is not available or does not fit the passenger's criteria or is not a valid seat.
    Would you like to reenter data (R) or Exit(E)-> e
    e
    
    ***  Main Aiport Menu ***
    
    L) List the flight numbers.
    I) Get Airplane flight information.
    A) Add passengers to a flight.
    O) Print Occupancy Chart for a flight.
    M) Print Manifest for a flight.
    Q) Quit.
    
    
    Enter choice -> m
    m
    Enter the flight number -> UA312
    UA312
    
    Manifest for flight UA312 to Dinnehotso
    1C   Barney Rubble
    2A   George Jetson
    6F   Sam Spade
    9A   Fred Flintstone
    10C  bad guy
    
    
    ***  Main Aiport Menu ***
    
    L) List the flight numbers.
    I) Get Airplane flight information.
    A) Add passengers to a flight.
    O) Print Occupancy Chart for a flight.
    M) Print Manifest for a flight.
    Q) Quit.
    
    
    Enter choice -> l
    l
    
    William and Mary Regional Airport
    
    UA312          Dinnehotso
    Delta222       Kayente
    USAir413       Cleveland
    TA414          Atlanta
    UA110          New York
    PanAm15        Chinle
    
    
    
    ***  Main Aiport Menu ***
    
    L) List the flight numbers.
    I) Get Airplane flight information.
    A) Add passengers to a flight.
    O) Print Occupancy Chart for a flight.
    M) Print Manifest for a flight.
    Q) Quit.
    
    
    Enter choice -> o
    o
    Enter the flight number -> PanAm15
    PanAm15
    
    
    Flight PanAm15 to Chinle
            A  B  C  D  E  F  G  H  I  J
    Row 1   FN FN FN FN FN FN FN FN FN FN
    Row 2   FN FN FN FN FN FN FN FN FN FN
    Row 3   FN FN FN FN FN FN FN FN FN FN
    Row 4   FN FN FN FN FN FN FN FN FN FN
    Row 5   FN FN FN FN FN FN FN FN FN FN
    Row 6   FN FN FN FN FN FN FN FN FN FN
    Row 7   EN EN EN EN EN EN EN EN EN EN
    Row 8   EN EN EN EN EN EN EN EN EN EN
    Row 9   EN EN EN EN EN EN EN EN EN EN
    Row 10  EN EN EN EN EN EN EN EN EN EN
    Row 11  EN EN EN EN EN EN EN EN EN EN
    Row 12  EN EN EN EN EN EN EN EN EN EN
    Row 13  EN EN EN EN EN EN EN EN EN EN
    Row 14  EN EN EN EN EN EN EN EN EN EN
    Row 15  EN EN EN EN EN EN EN EN EN EN
    Row 16  ES ES ES ES ES ES ES ES ES ES
    Row 17  ES ES ES ES ES ES ES ES ES ES
    Row 18  ES ES ES ES ES ES ES ES ES ES
    Row 19  ES ES ES ES ES ES ES ES ES ES
    Row 20  ES ES ES ES ES ES ES ES ES ES
    
    
    ***  Main Aiport Menu ***
    
    L) List the flight numbers.
    I) Get Airplane flight information.
    A) Add passengers to a flight.
    O) Print Occupancy Chart for a flight.
    M) Print Manifest for a flight.
    Q) Quit.
    
    
    Enter choice -> k
    k
    
    You've entered an invalid choice.
    
    ***  Main Aiport Menu ***
    
    L) List the flight numbers.
    I) Get Airplane flight information.
    A) Add passengers to a flight.
    O) Print Occupancy Chart for a flight.
    M) Print Manifest for a flight.
    Q) Quit.
    
    
    Enter choice -> q
    q
    
    Thank you for using the Flight reservation program.
    
    


    Specifications for Documentation and Format

    With the help of the Style Guide in your Lab manual, fully document your code following the javadoc conventions and include:


    Program Testing and Submission

    Information needed for testing this program are linked from the top of the page and can be imported (see below). Test your program thorougly with the data and sample output given before submitting.

    Submit your program file electronically. In Eclipse, right click on the project and import the files from /home/f85/debbie/cs141/Proj5. This will include the airplanes.txt file, testa.dat, and Proj5.java.

    Right click on the file submit.xml and select Run -< 1 Ant Build;. Messages will appear in the Console window. Be sure to determine whether you got the Build successful message to ensure that your electronic file submission for this program was successful.

    Honor Code. The honor code applies to all programming done in this course. Reread the CS Department's document: Programming Assignments and the Honor Code.


    Debbie Noonan, debbie@cs.wm.edu
    April 6, 2007