Flight Types - Assignment 3

moodusroundoSoftware and s/w Development

Aug 15, 2012 (4 years and 10 months ago)

208 views

CP
32
2
0

Assignment
3


Page
1

of
8

CP3220 Assignment 3


Flight Types



Background


Overview




Modify the Flight class from Assignment 2 and use it as a parent class for three
subclasses: CargoFlight, PassengerFlight, and TrainingFlight.



Exploit the inheritance relationship when writing
methods in the child classes.



Construct objects of the three child types from a file of flight data.



Starter Pack


You are given a NetBeans project with the GUI already built.



In the main form class, the action listener for the “Query” button is complete
.



Also in the form class, you are provided with several
other
methods, including:

o

countFlights
, which counts the number of flights in the file matching a specified
type (e.g., “Passenger”)

o

createLocations
, which creates an array of Location objects. Note t
hat this array
is declared at the top of the main form class.

o

findLocation
, which returns the Location object matching the specified location
code.



The Location class is complete. No changes are required.



Take note of the Common class. It contains some use
ful constants and methods for
formatting numbers.



The Data Files




The file “locations.csv” is the same file from Assignment 2.



The file “flights.csv” has changed from the previous assignment. It is described in detail
below.





CP
32
2
0

Assignment
3


Page
2

of
8


The File “flights.csv”



Each line contains either 6 or 7 pieces of
information, depending on the flight type.
(Training flights have 6 pieces; cargo and
passenger flights have 7.)

0.

Flight Type


th楳i楳 杵慲慮te敤 to
be one of the three strings “Cargo”,
“Passenger”, or “Training
”.



Flight Number

2.

Day of Week


“Sun”, “Mon” …
“Sat”



Departure Time


慮 楮te来爠
b整w敥n 0 慮T 2㌴㔮



Three
-
letter location code of the
flight’s destination.



Number of crew members

6.

For Cargo flights, this is the weight
of the flight’s cargo; for Passenger

楧it猬 楴 楳ithe nu浢敲 of
p慳獥a来牳g




Example
: the first line is Cargo flight QR75 departing on Sunday at 1:00pm to ADD. It has 7 crew
members and a cargo weight of 23,940kg.


Example
: the sixth line is Passenger flight QR100 departing on Sunday at
5:15pm to BKK. It has
5 crew members and 241 passengers.


Example
: the tenth line is Training flight QR12 departing on Sunday at 7:30am to CMB. It has 10
crew members.




CP
32
2
0

Assignment
3


Page
3

of
8


How to Proceed


Note
: For all code that you will write,
use the Javadoc

specifications

as a guide.



Part A


Write the Classes


1.

Write the Flight class.



The method
toDisplayFormat

should return this class’s data, formatted as shown in
the sample output.



Take note of the constant AVERAGE_PERSON_WEIGHT in the Common class.



The method
calculateWeight

should return the total weight of all the crew
members.

2.

Write the CargoFlight class.



This class inherits from Flight.



The method
calculateWeight

should
add

the weight of the cargo to the weight of the
crew.



The method
toDisplayFo
rmat

should
add

to the string produced by the Flight class.
Specifically, it should add the cargo weight and the calculated total weight to the
output. (See Expected Results.)

3.

Write the PassengerFlight class.



This class inherits from Flight.



The method
cal
culateWeight

should
add

the total weight of the passengers to the
weight of the crew.



The method
toDisplayFormat

should
add

to the string produced by the Flight class.
Specifically, it should add the number of passengers and the calculated total weight
to
the output. (See Expected Results.)

4.

Write the TrainingFlight class.



This class inherits from Flight.



There is no
calculateWeight

method. (
Why?
)



The method
toDisplayFormat

should
add

to the string produced by the Flight class.
Specifically, it should add th
e calculated total weight to the output. (See Expected
Results.)




CP
32
2
0

Assignment
3


Page
4

of
8


Part B


Write the Query methods


5.

Write the methods
create
CargoFlights

and
displayCargoFlights
.

6.

Run the program:



Enter the two file names, select “Cargo” from the drop
-
down list, and
press the
Query button.



You should see all of the cargo flights displayed correctly, as shown in the Expected
Output section.



At the end of the cargo flight listing, you will see a total weight of 0.

7.


Write the method
findTotalWeight

that takes an array of

CargoFlight as its parameter.

8.

Run the program:



At the end of the cargo flight listing, you should see the correct total weight, as
shown in the Expected Output section.

9.

Repeat steps 5
-
8 for PassengerFlight’s


i.e., write
create
Passenger
Flights
,
display
Pa
ssenger
Flights
, and
findTotalWeight(
Passenger
Flight[])
, run the program, and
verify that your output is correct.

10.

Repeat steps 5
-
8 for TrainingFlight’s


i.e., write
createTrainingFlights
,
displayTrainingFlights
, and
findTotalWeight(TrainingFlight[])
, run t
he program, and verify
that your output is correct.



Part C


Write the action listener for the “Display Summary” button


This method should produce the summary results as shown in the Expected Output section.



What to Hand In




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



Screen captures for several program runs, as shown above.


Documentation

and Style


At least 20% of 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 every
method.



Assignment or Test?



Page
5

of
8



Expected Output


CargoFlights







Assignment or Test?



Page
6

of
8

Passenger Flights







Assignment or Test?



Page
7

of
8

Training Flights







Assignment or Test?



Page
8

of
8


Summary