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 Flight objects.
Algorithm :
STEP1: Start the program
STEP2: Create a class with Flight with four instance
variables
called airLineName, flightName, originCity and
destinationCity.
STEP3: Define a constructor of Flight class that takes the
values
and the values for the instance variables of the Flight
class.
STEP4: Write accessor and mutator methods for all the instance
variables of Flight class.
STEP5: Define a method toString that returns the string
representation of the instance
variables of the class Flight.
STEP6: Create a test program called FlightTest.java
STEP7: In main method of the class, instantiate two Flight class
objects.
STEP8:Call the method toString on each Flight objects that prints
the description of
Flight class.
STEP9:Stop the program.
Java program :
/**
* The java program that demonstrates the Flight class . The main
method
* instantiates the Flight objects with the airlines name, flight
name, origin name
* and destination name. Then call toString method to display the
one line
* description of the Flight on console output.
*
* */
//FlightTest.java
public class FlightTest {
public static void main(String[] args) {
Flight indiObject=new
Flight("Indgo", "ABC", "HYD", "DEL");
System.out.println(indiObject.toString());
Flight kingObject=new
Flight("KinFisherAirLines", "XYZ", "NY", "DLS");
System.out.println(kingObject.toString());
}
}//end of the class
----------------------------------------------------------------------------------------------------------------------------
//Flight class
//Flight.java
public class Flight
{
//declare instance variables of class
private String airLineName;
private String flightName;
private String originCity;
private String destinationCity;
/*Constructor that sets the values for the instance
variables*/
public Flight(String airLineName, String
flightName,
String
originCity, String destinationCity) {
this.airLineName=airLineName;
this.flightName=flightName;
this.originCity=originCity;
this.destinationCity=destinationCity;
}
/**
* Method to get air line name
*/
public String getAirLineName() {
return airLineName;
}
/**
* Method to set air line name
*/
public void setAirLineName(String airLineName) {
this.airLineName =
airLineName;
}
/**
* Method to get flight name
*/
public String getFlightName() {
return flightName;
}
/**
* Method to set the flight name
*/
public void setFlightName(String flightName) {
this.flightName = flightName;
}
/**
* Method to get origin city
*/
public String getOriginCity() {
return originCity;
}
/**
* Method to set the origin city
*/
public void setOriginCity(String originCity) {
this.originCity = originCity;
}
/**
* Method to get destination city
*/
public String getDestinationCity() {
return destinationCity;
}
/**
* Method to set the destination city
*/
public void setDestinationCity(String destinationCity)
{
this.destinationCity =
destinationCity;
}
/*Method returns the one line desription of
flight*/
public String toString() {
return String.format("Airline Name:
%s Flight Name: %s Origin Name: %s Destination Name: %s",
airLineName,flightName,originCity,destinationCity);
}
}//End of Flight class
Sample Output:
Airline Name: Indgo Flight Name: ABC Origin Name: HYD
Destination Name: DEL
Airline Name: KinFisherAirLines Flight Name: XYZ Origin Name: NY
Destination Name: DLS
CODE:
class FlightTest {
public static void main(String[] args)
{
Flight obj1 = new Flight("Chegg",1234,"London","New york");
//Flight obj1 = new Flight();
System.out.println(obj1.name+"\n"+obj1.number+"\n"+obj1.origin+"\n"+obj1.destination);
System.out.println("get name - "+obj1.getName());
System.out.println("get nuber - "+obj1.getName());
System.out.println("get Origin - "+obj1.getName());
System.out.println("get Destination - "+obj1.getName());
obj1.setName("HomeworkLib1");
obj1.setNumber(2345);
obj1.setOrigin("HomeworkLib2");
obj1.setDestination("India");
System.out.println(obj1.name+"\n"+obj1.number+"\n"+obj1.origin+"\n"+obj1.destination);
}
static class Flight {
String name;
int number;
String origin;
String destination;
Flight(String name_t,int number_t,String origin_t,String destination_t)
{
name = name_t;
number = number_t;
origin = origin_t;
destination = destination_t;
}
public void setName(String name_t)
{
name = name_t;
}
public void setNumber(int number_t)
{
number = number_t;
}
public void setOrigin(String origin_t)
{
origin = origin_t;
}
public void setDestination(String destination_t)
{
destination = destination_t;
}
public String getName()
{
return name ;
}
public int getNumber()
{
return number;
}
public String setOrigin()
{
return origin ;
}
public String setDestination()
{
return destination;
}
}
}
OUTPUT:

Design and implement a class called Flight that represents an airline flight. It should contain instance data that represents the airline name
in java Write a class called Flight that represents an airline flight. (50 pts) It should contain instance data that represents the airline name, flight number, departure city, destination cities, and flight price. Define the Flight constructor to accept and initialize all instance data. Overload the Flight constructor such that the initial value of instance data airline name by Delta. Include getter and setter methods for all instance data. Include a toString method that returns a one-line description of the...
Write a class called Shelf that contains instance data that represents the length, breadth, and capacity of the shelf. Also include a boolean variable called occupied as instance data that represents whether the shelf is occupied or not. Define the Shelf constructor to accept and initialize the height, width, and capacity of the shelf. Each newly created Shelf is vacant (the constructor should initialize occupied to false). Include getter and setter methods for all instance data. Include a toString method...
cs55(java) please. Write a class called Book that contains instance data for the title, author, publisher, price, and copyright date. Define the Book constructor to accept and initialize this data. Include setter and getter methods for all instance data. Include a toString method that returns a nicely formatted, multi-line description of the book. Write another class called Bookshelf, which has name and array of Book objects. Bookself capacity is maximum of five books. Includes method for Bookself that adds, removes,...
Chapter 5 Assignment Read directions: In JAVA design and implement a class called Dog that contains instance data that represents the dog's name and dog's age. Define the Dog constructor to accept and initialize instance data. Include getter and setter methods for the name and age. Include a method to compute and return the age of the dog in "person years" (seven times age of dog. Include a toString method that returns a one-time description of the dog (example below)....
Can you please help me with with problem. please follow all the specific insturctions, and try to make simple for a beginner in java. Write a class called Shape that contains instance data that represents the name and number of sides of the shape. Define a constructor to initialize these values. Include mutator(setter) methods – with the this reference – for the instance data, and a toString method that returns a the shape data. Create a static variable to keep...
A java class named Book contains: instance data for the title, author, publisher and copyright year a constructor to accept and initialize the instance data variables set and get methods a toString() method to return a formatted, multi-line description of the book Produce a child class that inherits from Book. The class is called Dictionary. Dictonary must include: instance data that describes the number of words in the dictionary a constructor that takes in all information needed to describe a...
-please use java 3. Interface: Implement a program that creates an Interfacecalled Vehiclewith the following abstract methods(getters): getMake(), getModel(), getYear(), and creates a Classcalled Carthatimplements the Vehicleinterface. The Carclass also contains instance data that represents the make, model, and year of the carand the constructor to initialize these values.Create a driver class called CarTest, whose main method instantiates a Carobject with the following information: Chevrolet, Impala, 2019, and test the getter methods you implement. 4. Abstract Class: Implement the above...
Registration Language Java Step 1: Design a class called Student. The Student class should contain the following data: firstName lastName studentID totalCredits gpa Your class should implement the “sets” and “gets” for the class. Include methods: equals, compareTo, toString. Change the toString method (from class) to put each member variable on a new line. Step 2: Write a driver program to test that Student works correctly. Test is with 3 students as given in class. Step 3: Write a “registration”...
A) Please implement a Python script to define a student class with the following attributes (instance attributes): cwid: student’s CWID first_name : student’s first name last_name: student’s last name gender: student’s gender gpa: student’s gpa Please make these attributes as private ones so they have to be accessed via getter/setter methods or property. For this purpose, please define a getter/setter method and property for each of the attributes. Another thing you need to do is to define a constructor that...
In Java*
Please implement a class called "MyPet". It is designed as shown
in the following class diagram.
Four private instance variables: name (of the type String),
color (of the type String), gender (of the type char) and weight(of
the type double).
Three overloaded constructors:
a default constructor with no argument
a constructor which takes a string argument for name, and
a constructor with take two strings, a char and a double for
name, color, gender and weight respectively.
public...