A Flight Schedule - Assignment 2

pheasantarrogantSoftware and s/w Development

Aug 15, 2012 (5 years and 2 months ago)

284 views

CP3220 Assignment 2



Page
1

of
11

CP3220 Assignment 2


A Flight Schedule


Background


Overview




Write classes to represent airport locations, pilots, and flights.



Write a FlightSchedule

class that contains a schedule of flights and provides query
methods for returning useful information from the schedule.




CP3220 Assignment 2



Page
2

of
11



Starter Pack


You are given a NetBeans proj
ect with the GUI already built and the following classes:


Class

Given

Your Will Writ
e


Location



Everything


Nothing

Pilot



Data fields



“get” methods for the fields




Contructors



toDisplayFormat

Flight



Data fields



“get” methods for the fields




Constructors



toDisplayformat

FlightSchedule



Data field



Constructor



“get” method for the data
f楥iT



countFlightsByNumber



countFlightsToLocation



countFlightsToRegion



countFlightsByPilot




getFlightsByNumber



getFlightsToLocation



getFlightsToRegion



getFlightsByPilot


Assignment2MainForm



btnLoadActionPerformed



createLocations



displayFlights



findLocation



findPilot


Take note of the global variables

at
the top of this class
!



createPilots



createFlights



btnQueryActionPerformed




CP3220 Assignment 2



Page
3

of
11


The Data Files


The file “locations.csv” is required, but you do not need to process it. Here are the descriptions
of the other two files, which you do need to process.



Information about pilots (and copilots).
Each line
of the file contains

either

three

or
four

pieces of
information, separated by commas:

0.

Employee ID

1.

Pilot’s last name



Pilot’s first name



Pilot’s nic
k n慭攠⡯(W楯n慬a


䕸慭N汥l
:



The first line contains employee 10101, a pilot
named Theodore P. Welgoss. This pilot does
not have a nick name.



The sixth line contains employee 10106, a pilot
named Howard L. Galbreath, whose nick name
is “Skip”.



䄠w敥k汹 獣h敤ul攠of f汩lhW猠T数a牴in朠f牯洠Doha⸠
䕡捨 汩l攠of Whe f楬攠
c潮o慩a猠浩m業im 潦o
four

慮T
愠浡硩浵洠潦o
獩s

p楥捥i 潦 info牭rWi潮




Flight identifier

1.

Three
-
letter
day of week

2.

Departure Time (from 0 to 2345)

3.

Three letter location code

4.

Pilot ID (op
tional)

5.

Copilot ID (optional)


Examples
:



The first line specifies flight QR75 departing on
Sunday at 1300 to ADD, with pilot ID 10210
and copilot ID 10149.



The third line specifies flight QR49 departing
on Sunday at 915 to BAH, with pilot ID 10106
(no copi
lot assigned).



The fifth line specifies flight QR30 departing on
Sunday at 545 to BKK (no pilot or copilot
assigned).

CP3220 Assignment 2



Page
4

of
11


A New GUI Feature


The Combo Box


The GUI in this assignment uses a new feature called a Combo Box. This allows the user to
select from a drop
-
down list of choices.




When the user has selected an item from the list, the programmer (that’s you) can retrieve the
name of the selected item

by calling the method
getSelectedItem
, which is a method in the
ComboBox class (just like
getText

is a method in the TextField class).


Example:


Suppose the user has selected “Destination” from the drop
-
down list, as illustrated
above
. Also,
suppose that

the name of the combo box is “comboQuery”. Then the following code would
print the word “Destination” to the console:


String selection = comboQuery.getSelectedItem().toString();

System.out.println(selection);




CP3220 Assignment 2



Page
5

of
11


How to Proceed


Note
: For all code that you will write, the specifications required can be found in the Javadocs.


Part A


Display All Flights


1.

Write the Pilot class.



The class requires two constructors


one for pilots who have a nickname, and one
for pilots who don’t.



The
method
toDisplayFormat

should return a string of the form “
ID =
?
, Name =
?
,
Nick Name =
?” Note that it should not include the nickname if the pilot does not
have one


see the Expected Output for examples.

2.

In the Assignment2MainForm class, w
rite the meth
od
createPilots
.

3.

Write the Flight class.



Note that “destination” field is a Location object.



Note that the “pilot” and “copilot” fields are Pilot objects.



The class requires three constructors.

i.

All data is available.

ii.

All data except co
-
pilot is available.

(Use null for the co
-
pilot).

iii.

All data except pilot and co
-
pilot is available. (Use null for both pilot and co
-
pilot.)



Write the method
toDisplayFormat

which returns a string with the flight’s
information, as shown in the sample output.



This method should
make use of the
toDisplayFormat

methods in the
Location and Pilot classes.



If no pilot is assigned to this flight, state “NOT YET ASSIGNED”; similarly for
the copilot.

4.

In the Assignment2MainForm class, w
rite the method
createFlights
.



You will need to get a Location object and (possibly) Pilot object(s) for a flight


use
the methods
findLocation

and
findPilot
, which are provided to you.

5.

Run the program
:



Enter the three file names and press the “Load” button.



In the output area, you sho
uld see all of the flights displayed.



Verify that the output does not contain any null pilots or pilots with a nick name of
“none”.




CP3220 Assignment 2



Page
6

of
11


Part B


Querying the Flight Schedule


6.

In the FlightSchedule class, write the four methods
:




getFlightsByNumbe
r,

getFl
ightsToLocation
,

getFlightsToRegion
,

getFlightsByPilot



(Note that each method has a corresponding “count” helper method which is
already written.)



Hint
: Not every flight has a pilot


beware of NullPointerExceptions when writing
getFlightsByPilot
!

7.

In the

Assignment2MainForm class, w
rite the action listener for the

Query


button. Get the
selected item
, decide which “
getFlights
...” method to call, and display the returned results.


8.

Run the program.

Try the different query types with various inputs and verify that the
correct results are displayed.



What to Hand In




A print
-
out of all your code. Please format this as HTML.



Screen captures for several program runs, as shown above.


Documentation

and Style


A significant portion of the marks for the assignment will be
for programming style and
documentation.



Use meaningful variable names.



Use constants if appropriate.



Include plenty of comments,
including Javadoc comments for every class, and ev
ery
method

that you write
.





CP3220 Assignment 2



Page
7

of
11

Expected Output


All Flights





CP3220 Assignment 2



Page
8

of
11

Flights By Number






CP3220 Assignment 2



Page
9

of
11


Flights to Location






CP3220 Assignment 2



Page
10

of
11

Flights to Region






CP3220 Assignment 2



Page
11

of
11

Flights by Pilot