Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

For java programming Write a class called Flight that represents an airline flig

ID: 3535958 • Letter: F

Question

For java programming

Write a class called Flight that represents an airline flight. It should have fields for airline name, flight number, number of miles (distance between the cities traveled), and the flight's origin and destination cities. The origin and destination cities should be kept in an array (one dimensional array of size 2). In addition to constructor(s) and usual methods (getters, setters, toStrring), Flight class should have a mehtod called calculateFuel, which will calculate the amount of fuel that will be used for this flight and returns the fuel amount. In this method, if the number of miles is less than 1000, then multiply number of miles by 2; if it is more than 1000 but less than 3000, then multiply the miles by 1.75; if the number of miles is more than 3000, then multiply the miles by 1.5. The tester/driver, FlightTest, should read the airline name, flight number, flight's origin and destination, and the number of miles from a file, called input.txt, and then create a flight objects having read the information.

Explanation / Answer

// Flight class

import java.io.BufferedReader;

import java.io.FileReader;



public class Flight {

String airlineName;

int flightNumber;

double miles; // (distance between the cities traveled)

String flightCities[];

public Flight()

{

airlineName = "";

flightNumber = 0;

miles = 0.0;

flightCities = new String[2];

flightCities[0] ="";

flightCities[1] ="";

}

public Flight(String name, int num, double mile, String origin, String destination)

{

airlineName = name;

flightNumber = num;

miles = mile;

flightCities = new String[2];

flightCities[0] =origin;

flightCities[1] =destination;

}

public void setAirlineName(String name)

{

airlineName = name;

}

public void setFlightNumber(int num)

{

flightNumber = num;

}

public void setMiles(double mile)

{

miles = mile;

}

public void setOriginCity(String origin)

{

flightCities[0] =origin;

}

public void setDestinationCity(String destination)

{

flightCities[1] =destination;

}

public String getAirlineName()

{

return airlineName;

}

public int getFlightNumber()

{

return flightNumber;

}

public double getMiles()

{

return miles;

}

public String getOriginCity()

{

return flightCities[0];

}

public String getDestinationCity()

{

return flightCities[1];

}

public String toString()

{

String info = "Airline Name : "+airlineName+". Flight Number : "+flightNumber;

info+=". Distance between the cities traveled(in miles) : "+miles;

info+=". Origin City : "+flightCities[0]+". Destination City : "+flightCities[1];

return info;

}

public double calculateFuel()

{

if(miles < 1000.0)

return 2*miles;

else if(miles >= 1000 && miles < 3000.0)

return 1.75*miles;

else if(miles >= 3000.0)

return 1.5*miles;

else

return 0.0;

}

}