Class Flight
- java.lang.Object
-
- Flight
-
public class Flight extends java.lang.ObjectFlight.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.- Version:
- Sept 5, 2020
- Author:
- CS230 Staff (TM)
-
-
Constructor Summary
Constructors Constructor Description Flight(java.lang.String airline, int flNum, java.lang.String from, java.lang.String to)Creates Flight objects, given their characteristics
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.StringgetAirline()returns this flight's for airlinejava.lang.StringgetDestination()Gets the destination of this flightintgetFlightNumber()Getter for flightNum of this flightjava.lang.StringgetOrigin()returns the origin of this flightstatic voidmain(java.lang.String[] args)Driver, used to test this class.static FlightreadFlight(java.util.Scanner s)Reads from the keyboard the properties of a Flight.voidsetAirline(java.lang.String airline)Sets this flight's airlinevoidsetDestination(java.lang.String toCity)Sets the destination of this flightvoidsetFlightNumber(int flNum)Setter for flightNum of this flightvoidsetOrigin(java.lang.String fromCity)Sets the origin of this flight to the input onebooleanisAnAlternative(Flight f)Checks wether the origin and destination of the invoker flight match the origin and destination of inputted flight.booleanisAStopOver(Flight f)Checks wether the destination of the flight the same as origin of the inputted flight.java.lang.StringtoString()Returns a String representation of this flight
-
-
-
Constructor Detail
-
Flight
public Flight(java.lang.String airline, int flNum, java.lang.String from, java.lang.String to)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 Detail
-
getAirline
public java.lang.String getAirline()
returns this flight's for airline- Returns:
- The airline name
-
setAirline
public void setAirline(java.lang.String airline)
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
public java.lang.String getOrigin()
returns the origin of this flight- Returns:
- The origin city of the flight
-
setOrigin
public void setOrigin(java.lang.String fromCity)
Sets the origin of this flight to the input one- Parameters:
fromCity- The origin city of the flight
-
getDestination
public java.lang.String getDestination()
Gets the destination of this flight- Returns:
- The destination city of this flight
-
setDestination
public void setDestination(java.lang.String toCity)
Sets the destination of this flight- Parameters:
toCity- The destination city of this flight
-
isAnAlternative
public boolean isAnAlternative(Flight f)
Checks whether the invoker flight’s origin and destination are the same as the input flight’s origin and destination. Returns false otherwise.- Parameters:
f- flight- Returns:
- true if the invoker flight's origin and destination is the same as the origin and destination of the flight passed in.
-
isAStopOver
public boolean isAStopOver(Flight f)
Checks wether the destination of the flight is the same as origin of the flight that was passed in. It returns true if this is the case, false otherwise- Parameters:
f- flight- Returns:
- true if the first flight's destination is the same as the origin of the second.
-
toString
public java.lang.String toString()
Returns a String representation of this flight- Overrides:
toStringin classjava.lang.Object- Returns:
- The state of this flight, as a string
-
readFlight
public static Flight readFlight(java.util.Scanner s)
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
public static void main(java.lang.String[] args)
Driver, used to test this class.
-
-