Assignment 2
CSC 115, Fall 2002
Objectives:
- Experience with OO programs
- Experience understanding code
written by others
- Experience interpreting program
specifications in natural language
- Effective and correct use of
polymorphism
- Experience implementing and using
Interfaces
- Effective use of Exceptions and
Exception handling
- Effective use of Iterators and inner
classes
- Experience working with linked list
structures
- Effective use of program testing
Note: The assignment will be marked out 100 marks --
Part A is worth 15 marks, Part B is worth 85 marks. The assignment is worth 5% of your final grade.
Due dates for Parts A and B are provided below.
Problem:
You have been approached by a client who
operates a small no-frills (i.e. low-cost) airline and has asked you for a very
simple computer system that will eventually form the basis for a larger working
system. A programmer has already spent some time designing the main structure
of the program and in fact has even implemented some of the code.
Unfortunately, this programmer left the company rather suddenly without even
documenting their code! As a first task, you need to understand the
existing code that has been written and provide documentation for those
classes. Next you will need to implement some more of the code required for the
airline passenger system. The following lists the functional
requirements of the system.
Functional requirements:
The client wants the system to keep track of the following
information for each flight:
-
This system should keep track of the travellers checked in
for a flight.
-
There are two kinds of passengers -- ordinary passengers and
elite passengers. For each passenger, the system has to keep track of the
passenger's name, the seat number assigned and the meal assigned.
The system also has to keep track of miles travelled by the elite passengers.
-
In addition, to passengers, the system needs to keep track
of infants travelling on a flight recording the infant's name, their age (in
months), and the guardian (who must be a checked-in passenger). Infants
are not assigned seats or meals.
-
The system also must keep track of different flights.
For each flight, the system needs to record the flight number, the miles of the
flight, the number of seats on the plane and the list of travellers (i.e.
passengers and infants).
The client wants to be able to perform the
following actions with the airline system for each flight:
- Check-in both regular and elite
passengers. Each passenger is assigned a seat and the plane should fill
up starting at the first seat, without leaving any seats empty. There is
no priority seating for "Elite" bookings. It is not possible to cancel a
booking once it is made under any circumstances. Note if the plane is full (i.e. no
seats are left), the check-in procedure must generate an exception.
Each passenger is assigned a meal, either Chicken or Beef. Passengers in
an even numbered seat get Chicken, and passengers in odd numbered seats get
Beef. Infants are not assigned a meal. When an elite passenger is
checked in, their miles are increased by the miles of the flight.
- Check-in an infant for the flight
and add it to the list of travellers for the flight. Infants will sit with
their guardians so no seat or meal assignment is required. Note if the
infant is over 24 months, the infant check-in procedure must generate an
exception.
- Print an
ordered list of the travellers (passengers and infants) on a flight, starting
with the first seat assigned. For
passengers, the name of the passenger and the seat number assigned should be
printed. For infants, the name of the infant and the name of the
guardian should be printed. Such a list can be used by the crew to
check who is sitting in which seat.
- Print an ordered list of the food
assigned to the passengers, but in reverse order to the checked-in order.
The reversed order will make it easier for the air crew to serve meals from
the back of the plane. This list should list the passenger’s name and the
meal assigned (note infants are not assigned any meals so they should not be
included in this list).
- Print a list of the “Elite”
passengers in the order they arrived to check-in. This list should
provide the name of each passenger and the number of miles each passenger
currently has.
Instructions:
Part A
The previous programmer did some work for you already
but before you can start writing code you first have to understand what has been done. You have been provided with the following
classes:
Unfortunately, the files provided have not been
documented. Your first task is to add inline comments and Javadoc
comments to each of these files. Furthermore, to help you understand
the general scope of the program and the design of the various classes, you need
to draw a picture of how the different classes will be used in the software
system. You do not need to use any particular notation
for your diagram, but do provide a legend for your drawing so that others can
interpret it.
Deliverables and due date for Part A:
Part A is due at the end of your lab during
the week of October 14th (you must attend the lab you are registered for).
You need to start Part A before the lab, but you may finish
it in the lab and ask questions as required.
Furthermore, you should also have spent
some time thinking about Part B so that you can ask more pertinent questions
during this lab.
For Part A, hand in printouts of the
commented code, with your name, lab section, and student number in the
header comments. Also hand in your diagram (a neatly hand drawn diagram is
acceptable).
Hints:
- You should start Part A before your lab.
In particular you should draw the diagram and read the source code provided in
advance of the lab.
- A better understanding of what is required for Part B
will help you do the documentation and with drawing a diagram so you should
read Part B before doing Part A.
- The
javadoc commenting style is to be also used for the code we provide. These
are the comments that define the purpose, input, and expected output of each
of your public methods and classes.
- The
regular comments must contain instructions for programmers who may have to
modify your code at some later date. These comments should help the programmer
understand what the code is doing in plain language. You can assume that the
programmer is experienced enough to know what while
loops and
if-statements are.
Part B
Now that you have a better understanding of the code
provided, as well as insight about the general design and requirements for the
program, you need to do some more of the implementation. The
following lists the main things you need to do.
- You need to implement the TravellerList class.
Objects of this class will keep track of the flight travellers (passengers
and infants) for a particular flight. The general structure of the TravellerList class has already been specified by the TravellerListUtils
interface (see
TravellerListUtils.java).
- Implement the Flight class as specified by the
FlightUtils interface (see
FlightUtils.java). Recall from above that the Flight class needs to
keep track of the flight number, the miles to travel, the number of seats on
the plane, as well as the list of travellers. The Flight class is
also responsible for checking in passengers and infants, and assigning seats
and meals. Furthermore, the Flight class needs to provide several
methods for printing lists of the travellers on the plane (see the FlightUtils.java file and the above description of the
functional requirements for details on the required methods).
Note, your program does not (at this time) need to provide a user interface
for getting details on passengers and infants. You should hardcode the
passengers, elite passengers and infants in your Tester class (see item #5
below).
- In order for the Flight class to provide the required
printouts of passengers, you need to add several private inner class
Iterators to the TravellerList class. The first iterator iterates
through the traveller list in FIFO (first-in, first-out) order. The
second iterator iterates the list in LIFO (last-in, first-out) order, and the
third iterator is a specialized iterator that only iterates through the elite
passengers in FIFO order.
- The program should handle at least
two exceptions: If the user of the program tries to book a space for an
infant that is older than 24 months, the checkinInfant method in the Flight
class must throw an InfantTooOldException. We provide the class for
this exception (see
InfantTooOldException.java).
Also, if the user of the program tries to book a seat for a passenger when the
plane is full, the checkinPassenger method in the Flight class must throw an
OverBookedException. We also provided the class for this exception
(see OverBookedException.java).
You should catch these exceptions in your Tester class
(see next item).
- We have provided a fairly simple
Tester class for testing the program (see
Tester.java and output.txt). You
should add more passengers and infants to check in within the main method in this class to test how robust your program is.
Deliverables and due date
for Part B:
Part B is due on Tuesday, October 22nd by
6pm. Submit all commented .java files by electronic submission page BEFORE 6 PM
on the 22nd. You should also electronically submit the commented files from
Part A. Please ensure that your code is submitted before this time, as the
submission program will not accept late assignments. Please also be sure that
your submission compiles and runs before you submit these files. Also submit a
printout of all your source code, stapled together, in class on the following
day -- Wednesday, 23rd October.
Summary of files to implement for Part B:
- Flight.java (Flight implements
FlightUtils)
- TravellerList.java (TravellerList
implements TravellerListUtils)
- Tester.java (expand on the simple
one we provided)
Remember to submit all documented source files from both Part
A and Part B.
Rules and Hints:
- You must not alter or vary from the
interfaces and specifications provided.
- File headers must contain your name
and/or your student number.
- The
javadoc commenting style is to be also used for the code you added in Part
B. These are the comments that define the purpose, input, and expected output
of each of your public methods and classes.
- The
regular comments must contain instructions for programmers who may have to
modify your code at some later date. These comments should help the programmer
understand what the code is doing in plain language. You can assume that the
programmer is intelligent to know what while
loops and
if-statements are.
- Your program should be robust, unit
test each of the classes and test your program carefully for boundary cases
and unusual input. Expand the Tester class accordingly, and expand on
the main methods in each of the TravellerList and Flight classes you wrote.
Note that we will use a more detailed Tester class to test your code more
thoroughly.
- Implement just one iterator first
and get it working before attempting the other iterators. Make
liberal use of the toString methods for debugging purposes.
Bonus:
In Tester instead of creating the passengers and infants one at a time, read
in the data required for the program from a file. (Max of 10 bonus marks).
Notice:
If you find any errors or
inconsistencies in this document, report them immediately to
csc115@csc.uvic.ca. Notification of changes (or clarifications) will be
posted on the CSC115 Forum on
WebBoard .