
3.Flights Design and implement a class called Flight that represents an airline flight. It should contain instance data that represents the airline name, flight number, and the flight's origin and destination cities. Define the Flight constructor to accept and initialize all instance data. Include getter and setter methods for all instance data. Include a toString method that returns a one-line description of the flight. Create a driver class called FlightTest, whose main method instantiates and updates several (at least 5) Flight objects.

class Flight{
private String airline, origin, destination;
private int flightNumber;
public Flight (String airline,int flightNumber, String origin, String destination){
this.airline = airline;
this.flightNumber = flightNumber;
this.origin = origin;
this.destination = destination;
}
public String getAirline ()
{
return airline;
}
public int getFlightNumber ()
{
return flightNumber;
}
public String getOrigin ()
{
return origin;
}
public String getDestination ()
{
return destination;
}
public void setAirline (String airline)
{
this.airline = airline;
}
public void setFlightNumber (int flightNumber)
{
this.flightNumber = flightNumber;
}
public void setOrigin (String origin)
{
this.origin = origin;
}
public void setDestination (String destination)
{
this.destination = destination;
}
public String toString ()
{
return airline + ", " + flightNumber + " -- From: " + origin +", To: " + destination;
}
}
class FlightTest{
public static void main (String[] args)
{
Flight f1 = new Flight ("US Air",111, "Boston", "Los Angeles" );
Flight f2 = new Flight ("Indian Airlines",222, "New Delhi", "New York" );
Flight f3 = new Flight ("Jet Airways", 333,"New Delhi", "Singapore" );
Flight f4 = new Flight ("Kingfisher Airlines", 444,"New Delhi", "Paris" );
Flight f5 = new Flight ("Deccan Airlines", 555,"New Delhi", "Chicago" );
System.out.println (f1);
System.out.println (f2);
System.out.println (f3);
System.out.println (f4);
System.out.println (f5);
System.out.println();
System.out.print("Flight 1 \t old flight number: " + f1.getFlightNumber());
f1.setFlightNumber(101);
System.out.println ("\t New flight number: " + f1.getFlightNumber());
System.out.print("Flight 5 \t old destination place: " + f5.getDestination());
f5.setDestination("Moscow");
System.out.println ("\t New destination place: " + f1.getDestination());
}
}

thank you alot for the answer
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.