CP
3210
Assignment
6
Page
1
of
14
CP
3210
Assignment
6
–
Polymorphism
Overview
This assignment is a continuation of Assignment 5.
Modify the code to load the flights from the input file so that it works polymorphically.
Modify
the
classes from Asssignment 5 so that they implement the int
erfaces
Formattable and Weighable.
Write
three utility classes to:
o
extract
flights based on certain criteria;
o
format
flights in different ways;
o
calculate
weight
statistics about flights
.
Starter Pack
You are given a NetBeans pro
ject with the GUI alread
y built and
some
of the code completed.
In the main form class,
the action l
istener for the “
Load Data
” button
is complete.
o
Note that it creates a FlightSchedule object and stores it in the variable
schedule
which is declared at the top of the class.
o
You w
ill
make extensive use of this
schedule
variable.
You are also given the action listeners for the first row of buttons
in the “Displays” area
:
o
btnAllDislayFormatActionPerformed
displays all flights in display format
o
btnAllArchiveFormatActionPerformed
displ
ays all flights in archive format
o
btnAllWeightInfoActionPerformed
displays the total, average, maximum, and
minimum weights for all flights.
Also in the form class
,
you
are provided with
several
other
methods, including:
o
createLocations
, which creates an a
rray of Location objects. Note that this array
is declared at the top of the main form class.
o
findLocation
, which returns the Location object matching the specified code.
The Location class is complete. No changes are required.
The
Data
Files
The file “
locations.csv” is the same file from Assignment 2.
The file “flights.csv”
is the same file from Assignment 5.
CP
3210
Assignment
6
Page
2
of
14
How to Proceed
Note
: For all code that you will write,
use the Javadoc specifications
as a guide.
Part A
–
Display All Flights in Display Forma
t and Archive Format
1.
Take a moment to examine the code in the action listener for the “Load Data” button.
Note that it calls a method
nam
ed
createFlights
, which you will write.
Also note that it creates a FlightSchedule object and stores it in the
schedu
le
variable, which is declared at the top of the form class.
2.
Make the Flight class abstract.
3.
Add the abstract method
getFlightType
to the Flight class. Make the required changes to
the child classes.
4.
Make the Flight class implement the interfaces Formattab
le and Weighable.
Make whatever changes are required to the Flight class and the child classes.
Note that the
toDisplayFormat
and
toArchiveFormat
methods should now include
the flight type.
5.
Write the method
createFlights
in the main form class. (Note that
the three separate
“create” methods from Assignment 5 are no longer required!)
6.
Write the
methods in the
Formatter class.
Note that it
both methods expect an
array of type Formattable.
Note that
formatForDisplay
returns one large string containing all items
, whereas
formatForArchive
returns a String array with one item per element.
7.
Write the FlightSchedule class.
Note that the constructor requires an array of type Flight.
The constructor should also construct the Extractor, Formatter, and WeightAnalyzer
obje
cts. (These classes’ constructors do not require any
parameters
.)
8.
Un
-
comment the indicated line in the action listeners for the first “Display Format” button
and the first “Archive Format” button.
9.
Run the program:
Enter the two file names and press the “Lo
ad Data” button.
Ensure that there are no errors in the console area, such as NullPointerException or
ArrayIndexOutOfBoundsException.
Press the first “Display Format” button (the one beside the label “All Flights”).
You should see all flights shown in disp
lay format.
Press the first “Archive Format
”
button.
You should see all flights shown in archive format.
CP
3210
Assignment
6
Page
3
of
14
Part B
–
Display Weight Statistics for All Flights
10.
Write the
methods in the
WeightAnalyzer class according to the javadocs.
Note that all methods e
xpect an array of type Weighable.
11.
Un
-
comment the indicated lines in the action listeners for the first “Weight Info” button.
12.
Run the program:
Enter the two file names and press the “Load Data” button.
Press the first “Weight Info” button (the one beside th
e label “All Flights”).
You should see the weight statistics for all flights displayed.
Part C
–
Specific Flight Types
13.
Write the
extractFlightType
method in the Extractor class according to the javadocs.
14.
Write the action listeners for the
second
row of b
uttons (the
three
buttons beside the
“Flight Type” text field
)
.
15.
Run the program and test the buttons for the flight type “Passenger”.
16.
You should see the correct output for passenger flights only.
Part D
–
Flights to Specific Destinations
17.
Write the
extrac
t
Destination
method in the Extractor class according to the javadocs.
18.
Write the action listeners for the
third
row of buttons (the buttons beside the “Flight Type”
text field
)
.
19.
Run the program and test the buttons for the destination “CGK”.
20.
You should see
the correct output only for flights to CGK.
What to Hand In
A print
-
out of all your code. Please format this as HTML.
Screen captures for several program runs, as shown
in the Expected Output
.
Documentation
and Style
At least 20% of the assignment wil
l 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 method.
CP
3210
Assignment
6
Page
4
of
14
Expected Output
Part A
–
Display All Flights in Display Format
and Archive Format
CP
3210
Assignment
6
Page
5
of
14
CP
3210
Assignment
6
Page
6
of
14
CP
3210
Assignment
6
Page
7
of
14
CP
3210
Assignment
6
Page
8
of
14
Part B
–
Display Weight Statistics for All Flights
CP
3210
Assignment
6
Page
9
of
14
Part C
–
Specific Flight Types
CP
3210
Assignment
6
Page
10
of
14
CP
3210
Assignment
6
Page
11
of
14
CP
3210
Assignment
6
Page
12
of
14
Part D
–
Flights to Specific Destinations
CP
3210
Assignment
6
Page
13
of
14
CP
3210
Assignment
6
Page
14
of
14
Enter the password to open this PDF file:
File name:
-
File size:
-
Title:
-
Author:
-
Subject:
-
Keywords:
-
Creation Date:
-
Modification Date:
-
Creator:
-
PDF Producer:
-
PDF Version:
-
Page Count:
-
Preparing document for printing…
0%
Comments 0
Log in to post a comment