Project 6
Come Fly With Me Revisited
Due: Wednesday, May 2, 8 AM
Submit Project: Proj6
Required Files: Proj6.java,
Airport.java,
Airplane.java,
Seat.java,
Input File: airplanes.txt
Grading Header: header.txt
Test data: testa.dat
Model Output: out.dat
Again, moving onto the next topic, this project incorporates linked lists into
your already created project from proj5. Some additional functionality will
also be added to this project, to incorporate some of the routines you wrote
but never used in the last project, as well as some new stuff.
The main
program should be in Proj6.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. (If you don't have a functioning project 5, you can get a
version from me. You need to come see me with a flash drive, or some other
portable medium, and I will make you a copy of my project 5.)
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 LINKED LIST of airplanes in order by
flight number. In
addition there is a constant
for the name of the airport. Your program must
first read the flight information into the LINKED LIST of planes (I've written
the code that reads the flight information for
you) and as they are read in, they need to be inserted into the list in order
by destination. Proj6.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. There will
also be new menu options to handle adding planes to the list of planes,
changing the number of first class rows,
changing the number of non-smoking rows, and removing passengers from a plane.
Now working from the inside out, these are the classes you will need:
Seat.java (this is the same)
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.
removePassenger() - This method allows the entry of a passenger's
name. Then it should search the plane looking for this passenger. If found he
should be removed from the plane (set his occupant value to the empty string).
If not found, an appropriate error message should be output.
available() - determines if the seat if available
appropriate() - determines if the seat fits the customer's criteria
Airport.java
This class contains a LINKED LIST of planes. I've also included a String with the
airport name as a public constant. I've also included the Node class for the
linked list node which contains an Airplane object and a pointer to the next
node. Some of the methods needed are:
readAirplanes() - This method reads flight information ultimately
inserting each flight into an linked list of flights in alpha order by flight number.
The information is coming from an external file called airplanes.txt. I
have written this method for you. You should study it and understand
how it works. However, there is a call to insert() in this method and you
must write the code to handle the insert. (Look at Ordered.java in the
examples for chapter 12, please).
There is a try/catch block to make sure the file is there.
It prints a count of how many flights have been read in.
After this method runs, the airport list
should have the flight information in it.
insert() - This should be called from readAirplanes() and addPlanes() and should
take a plane object. This plane object should be inserted into the linked list
in order by flight number.
addPlane() - This should allow the entry of the flight number,
the destination, the number of rows, the number of seats/row, the number of
rows in first class and the number of non-smoking rows. Assume all data
entered here will be good data. Then create a new plane and insert it into
the list of planes in alpha order by flight number.
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().
removePassengers() - This takes in a flightNumber and the Scanner
and if the flight exists it should call upon Airplane's removePassengers().
changeFirstClass() - This takes a flightNumber and an integer for
the new number of rows in first class (entered in main). If the flight exists,
it should call Airplane's setFirstClassRows().
changeNonSmoking() - this takes a flightNumber and an integer for
the new number of non-smoking rows (entered in main). If the flight exists, it
should call Airplane's setNonSmoking().
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 a pointer to the proper flight node if the flight exists. If the
flight doesn't exist, a null is returned.
Many routines in here may need to be changed because of the new data
structure. However many of them looking exactly alike, so once you figure out
how to change one, the rest should be easy.
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
P) Add new planes to the airport's list of planes.
A) Add passengers to a flight
R) Remove passengers from a flight.
F) Change number of first class rows
N) Change number of non-smoking rows
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 'P' is chosen, new plane information should be entered and this new plane
should be added to the list of planes.
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 'R' is chosen, the flight number should be entered and verified. If it
exists,
a passenger's name should be entered, and that person
should be deleted from the plane's log
If 'F' is chosen, enter the flight number, verify it and if it exists,
a new number of first class rows is entered, and the plane's
information is updated accordingly.
If 'N' is chosen, enter a flight number, verify it and then
a new number of non-smoking rows is entered, and the plane's
information is updated accordingly.
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 (not from keyboard - no echo printing shown)
See out.dat from above.
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:
- A class prologue at the top of each of your program files.
The @author tag must
contain your name, your e-mail address, your
W&M phone extension.
The prologue
must also contain a full description of the program.
- Each method should include a javadoc comment about what the method
does. In addition if there are parameters, there should be an @param
tag for each one. If the method returns a value, there should be an
@return tag explaining that.
- Each closing brace must be commented, eg:
} // main
- All variables should be on an individual line and appropriately commented.
- Correct formatting requires that the code must be reasonably and
consistently indented.
- Avoid line wrapping. Split a line across two lines if it is going to occur.
- Horizontal and vertical white
space must be used reasonably and consistently.
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/Proj6. This will
include the airplanes.txt file, testa.dat, and all the .java files.
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 17, 2007