Class Flight
java.lang.Object
Flight
Flight.java
Implements a class named Flight that represents an airline flight. It contains instance data that represent the name of the airline, the flight number, the flights origin and destination cities. A static method readFlight() is used to get values from the keyboard.
In addition to the getters and setters, the class provides a String representation of Flight object.
The main shows the use of a driver/testing program
Implements a class named Flight that represents an airline flight. It contains instance data that represent the name of the airline, the flight number, the flights origin and destination cities. A static method readFlight() is used to get values from the keyboard.
In addition to the getters and setters, the class provides a String representation of Flight object.
The main shows the use of a driver/testing program
- Version:
- Sept 10, 2022 Feb 2024: SK added isAnAlternative(). Changed isAStopOver() from static to instance
- Author:
- CS230 Staff
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionreturns this flight's for airlineGets the destination of this flightint
Getter for flightNum of this flightreturns the origin of this flightboolean
isAnAlternative
(Flight other) Checks whether the invoking flight and the input one are alternatives, ie the have the same origin and the same destination.boolean
Checks whether the destination of this flight is the same as origin of the input one.static void
Driver, used to test this class.static Flight
Reads from the keyboard the properties of a Flight.void
setAirline
(String airline) Sets this flight's airlinevoid
setDestination
(String toCity) Sets the destination of this flightvoid
setFlightNumber
(int flNum) Setter for flightNum of this flightvoid
Sets the origin of this flight to the input onetoString()
Returns a String representation of this flight
-
Constructor Details
-
Flight
Creates Flight objects, given their characteristics- Parameters:
airline
- The name of the airlineflNum
- The flight numberfrom
- The city of originto
- The city of destination
-
-
Method Details
-
getAirline
returns this flight's for airline- Returns:
- The airline name
-
setAirline
Sets this flight's airline- Parameters:
airline
- The updated name of the airline for this flight
-
getFlightNumber
public int getFlightNumber()Getter for flightNum of this flight- Returns:
- The flight number
-
setFlightNumber
public void setFlightNumber(int flNum) Setter for flightNum of this flight- Parameters:
flNum
- The number for this flight
-
getOrigin
returns the origin of this flight- Returns:
- The origin city of the flight
-
setOrigin
Sets the origin of this flight to the input one- Parameters:
fromCity
- The origin city of the flight
-
getDestination
Gets the destination of this flight- Returns:
- The destination city of this flight
-
setDestination
Sets the destination of this flight- Parameters:
toCity
- The destination city of this flight
-
isAStopOver
Checks whether the destination of this flight is the same as origin of the input one. It returns true if this is the case, false otherwise- Parameters:
f
- the flight to check its origine- Returns:
- true if this flight's destination is the same as the origin of the input flight.
-
isAnAlternative
Checks whether the invoking flight and the input one are alternatives, ie the have the same origin and the same destination. Returns true if so, false otherwise.- Parameters:
f
- the flight to check its origine and destination for being equal to the ones of the invokig flight- Returns:
- true if this flight's origin and destination are the same as the ones in the input flight.
-
toString
Returns a String representation of this flight -
readFlight
Reads from the keyboard the properties of a Flight. Returns the Flight object. Used in main(). Notice that this is a "static" method, because it is to be used by the static main().- Parameters:
s
- the Scanner object to be used for reading user input- Returns:
- The flight as entered by the user
-
main
Driver, used to test this class.
-