starting foreach
Create a class named Airport
that keeps track of the flights that
use a certain airport, either as their origin or destination.
For this exercise you are NOT allowed to use any of Java's Arrays class. Just use arrays of Objects as we did in lectures.
0. Draw your class objects as you design and before you code them. You will need to submit a picture of your drawing, so keep it (reasonably) neat and clean. If you need a reminder on how to draw these class objects, make sure to revisit the slides and see the CD and CDCollection objects.
Your class should contain the following:
1. Instance variables
2. Constructor
It should take the name of the airport as an input. Think of what the purpose of a constructor is!
3. Instance methods
addFlight()
: it takes a Flight object as input, and adds it to the array of Flights. If there is not enough space for a flight to be added, create a larger array.
toString()
: as usual, this method should provide a String representation of an object
of type Airport. This representation should contain the airport's name and capacity, the number
of flights it currently serves, as well as a listing of those flights.
deleteFlight()
: it takes a Flight object as input and removes this flight from the airport. Make sure that the resulting array of flights contains no "holes" after the removal of a flight.
findFlightsByAirline()
: takes as input the name of an airline, and returns an array with all the Flights of this airline that use this airport.
printFlightsByAirline()
: given the name of an airline,
it prints all the flights of this airline that are using this airport. While there are many ways to implement such a method, make sure your implementation uses the previous to compute the array of flights to print.4. No main() is required in the Airport class but create a separate client class
Instead, create another client class called LoganAirport.java
. This class contains only a main()
method. It main purpose is to test your Airport
class. Make sure you test your methods as you develop your code. Start by creating an instance of type Airport
called logan
, and some Flight
instances.
5. Write good javadoc Make sure you add nice javadoc to your code that includes:
above the class documentation
(but below any import
statements): Provide a quick description of what this class is doing.
Use the @author
and @version
tags.
above a method documentation
: For every method provide a short
sentence to succinctly and accurately describe what this method is doing. Also, use the @param
and @return
javadoc tags as needed.
in-line comments
: Add them only as appropriately, to document your code. You should strike for a balance here: Ideally, the reader of your code should be able to follow it by just reading the comments. At the same time, you should not document the obvious.
6. Testing
Save the printout of the LoganAirport
class into a file named LoganTesting.txt
. For inspiration look at our own DriverTesting.txt driver.
Airport.java
, your LoganAirport.java
, your LoganTesting.txt
, and your picture of your drawing of the class objects to Gradescope. Flight.java
code we linked above, unless it is your own Flight.java
code (not our sample solutions from the previous assignment.) Remember that in Gradescope you have to upload all the files at once. Every submission you do overwrites the previous one, so if you upload one file at a time, only the last will be saved.
Check your submission to make sure the right files have been submitted.