Assume Flight is a class whose objects represent airline fli

Assume Flight is a class whose objects represent airline flights. Assume a constructor of the Flight class accepts four parameters – the name of the airline, the flight number, the origination city name and the destination city name. Also assume that this class contains a setter method for each of its data fields, such as setFlightNumber().

1. Write a declaration for a variable named flightSchedule that is an array of 10 flights.

2. Write a statement that sets the flight number of the last flight in the flightSchedule array to 12345.

Solution

/**
* @author
*
*/
public class Flight {

   String nameOfAirLine;
   int flightNumber;
   String originationCity;
   String destinationCity;

   /**
   * @param nameOfAirLine
   * @param flightNumber
   * @param originationCity
   * @param destinationCity
   */
   public Flight(String nameOfAirLine, int flightNumber,
           String originationCity, String destinationCity) {
       this.nameOfAirLine = nameOfAirLine;
       this.flightNumber = flightNumber;
       this.originationCity = originationCity;
       this.destinationCity = destinationCity;
   }

   /**
   * @return the nameOfAirLine
   */
   public String getNameOfAirLine() {
       return nameOfAirLine;
   }

   /**
   * @param nameOfAirLine
   * the nameOfAirLine to set
   */
   public void setNameOfAirLine(String nameOfAirLine) {
       this.nameOfAirLine = nameOfAirLine;
   }

   /**
   * @return the flightNumber
   */
   public int getFlightNumber() {
       return flightNumber;
   }

   /**
   * @param flightNumber
   * the flightNumber to set
   */
   public void setFlightNumber(int flightNumber) {
       this.flightNumber = flightNumber;
   }

   /**
   * @return the originationCity
   */
   public String getOriginationCity() {
       return originationCity;
   }

   /**
   * @param originationCity
   * the originationCity to set
   */
   public void setOriginationCity(String originationCity) {
       this.originationCity = originationCity;
   }

   /**
   * @return the destinationCity
   */
   public String getDestinationCity() {
       return destinationCity;
   }

   /**
   * @param destinationCity
   * the destinationCity to set
   */
   public void setDestinationCity(String destinationCity) {
       this.destinationCity = destinationCity;
   }

   public static void main(String[] args) {

       Flight[] flightSchedule = new Flight[10];
       flightSchedule[9].setFlightNumber(12345);
   }

}

Assume Flight is a class whose objects represent airline flights. Assume a constructor of the Flight class accepts four parameters – the name of the airline, th
Assume Flight is a class whose objects represent airline flights. Assume a constructor of the Flight class accepts four parameters – the name of the airline, th

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site