Class Flight


  • public class Flight
    extends java.lang.Object
    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.
    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.String getAirline()
      returns this flight's for airline
      java.lang.String getDestination()
      Gets the destination of this flight
      int getFlightNumber()
      Getter for flightNum of this flight
      java.lang.String getOrigin()
      returns the origin of this flight
      static void main​(java.lang.String[] args)
      Driver, used to test this class.
      static Flight readFlight​(java.util.Scanner s)
      Reads from the keyboard the properties of a Flight.
      void setAirline​(java.lang.String airline)
      Sets this flight's airline
      void setDestination​(java.lang.String toCity)
      Sets the destination of this flight
      void setFlightNumber​(int flNum)
      Setter for flightNum of this flight
      void setOrigin​(java.lang.String fromCity)
      Sets the origin of this flight to the input one
      boolean isAStopOver​(Flight f)
      Checks weather the destination of the flight the same as origin of the inputted flight.
      java.lang.String toString()
      Returns a String representation of this flight
      • Methods inherited from class java.lang.Object

        clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • 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 airline
        flNum - The flight number
        from - The city of origin
        to - 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
      • isAStopOver

        public  boolean isAStopOver​(Flight f)
        Checks weather 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:
        toString in class java.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.