Create a Flight class that uses the Plane and Time class Thi

Create a Flight class that uses the Plane and Time class. This class will represent a flight between two airports, using a specific Plane, and departing at a specific Time. It should contain a constructor, 7 instance variables (plane, flight number, cost, departure, duration, source, destination), and 9 methods (see below). [25 points] overloaded constructor: Creates a Flight object that is setup up with a Plane, a flight number, a cost, a departure Time, a duration time, a source Airport, and a destination Airport. getPlane(): Returns the Plane that operates this flight. getNumber(): Returns the flight number. getCost(): Returns the flight cost. getDestination(): Returns the destination Airport. getDeparture(): Returns the departure Time. getArrival(): Returns a Time object with the arrival time (computed from the departure time and duration). getSource(): Returns a Airport object for the departure location. toOverviewString(): Returns a String representing an overview of the flight. Use NumberFormat to display the price. See the sample output for an example. toDetailedString(): Returns a String representing the flight\'s detail information. See the sample output for an example.

Solution

import java.text.NumberFormat;

public class Flight{
   Plane plane;
   int flightNumber;
   double cost;
   Time departure;
   int duration;
   String source;
   String destination;
   public Flight(Plane plane, int flightNumber, double cost, Time departure, int duration, String source, String destination) {
       this.plane = plane;
       this.flightNumber = flightNumber;
       this.cost = cost;
       this.departure = departure;
       this.duration = duration;
       this.source = source;
       this.destination = destination;
   }
   Plane getPlane() {
       return plane;
   }
   int getFlightNumber() {
       return flightNumber;
   }
   double getCost() {
       return cost;
   }
   Time getDeparture() {
       return departure;
   }
   int getDuration() {
       return duration;
   }
   String getSource() {
       return source;
   }
   String getDestination() {
       return destination;
   }
  
   String toOverviewString(){
       NumberFormat nf = NumberFormat.getInstance();
       nf.setMaximumFractionDigits(2);
       return \"Departure: \" + departure + \", Source: \" + source + \", Destination: \" + destination + \", Price: \" + nf.format(cost);
   }
  
   String toDetailedString(){
       NumberFormat nf = NumberFormat.getInstance();
       nf.setMaximumFractionDigits(2);
       return \"Flight number: \" + flightNumber + \", Departure: \" + departure + \", Source: \" + source + \", Destination: \" + destination + \", Price: \" + nf.format(cost) + \"Time of travel: \" + duration;
   }
}

Create a Flight class that uses the Plane and Time class. This class will represent a flight between two airports, using a specific Plane, and departing at a sp
Create a Flight class that uses the Plane and Time class. This class will represent a flight between two airports, using a specific Plane, and departing at a sp

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site