starting foreach
Implement a class called Flight (here is the Flight javadoc) to represents an airline flight.
The following properties represent a Flight object:
Create a constructor for a Flight object. This should take as input all the needed information to create a flight. Think carefully: how many parameters should it have? What types should these parameters be?
toString() As with any other class you write, define a toString() method to provide the means of printing the contents of the object in an informative and concise way. Don't forget to use this method as you test your code in the main().
isAnAlternative() a predicate method that takes as input a flight and returns true iff (if and only if) the invoker flight's origin and destination are the same as the input flight's origin and destination.
Create the following methods:
readFlight():
a static method that asks and collects from the user all the information regarding a flight. Using this information, it creates a Flight, and returns it. This method takes as input a Scanner
.
It is important that you write code in your main()
method to test your program thoroughly. In it create a few Flight objects, and test all your methods on them. You can take a look at the result of (this testing code) for inspiration. Save the results of your testing into FlightTesting.txt
to be submitted with your source code.
Our experience shows that early-stage programmers make a few common mistakes that could be avoided with a more careful final reading of the specifications (i.e., the description of the assignment in our case). We thought of helping you in this careful reading by adding here a few items to review before submission:
Testing getOrigin. Expecting: BOS. Producing: BOS
).Flight.java
and your FlightTesting.txt
that contains the results of your testing.