Question
Flight Exercise Write a class called Flight that contains instance data to represent the airline name, flight number, and the flights origin and destination cities.
Flight Exercise
Write a class called Flight that contains instance data to represent the airline name, flight number, and the flights origin and destination cities. Define the flight constructor to accept or initialize all instance data. Include mutator(setter) methods for all instance data, and a toString method that returns the data of the Flight. Create a static variable to keep track of the number of flight objects and a static method to return the number of flights recorded. Create a driver class called FlightTest, whose main method instantiates and updates several Flight objects.
In the Flight class you will need:
Private members of the class to store the airline name, flight number, flight origin and destination cities A static variable to store the number of Flight objects Two constructors: The first constructor should not accept any values during instantiation (This constructor can initialize the members to an empty string or dash - i.e. or 0). The second constructor should accept all values for the members during instantiation. The static variable should be incremented in each version of the constructor Mutator methods for each member of the class You will need these to pass values to the second object. A static method to return the number of flights This will also serve as the accessor example A toString method to output the information on each flight
In the FlightTest driver, you will need:
At least two flight objects At least one object must be initialized with the constructor that accepts no parameters At least one object can be hardcoded by passing values through the constructor A Scanner object to get information for one (or more) of the objects Local variables (as needed) to store information To referene the mutators for one of your objects To reference the static method created in the class
A sample of the output is shown below. (Output does not have to be exact - you can create any situation that you like but your code must be able to show successful use of all components of the class and driver programs.)
Here is the information for the first part of your flight: American Airlines 1719 -- From: Tampa Bay, To: Las Vegas
Please enter the information for the second part of the flight: Airline: Delta Origin for connecting flight: Las Vegas Destination for connecting flight: Honolulu Flight Number: 1854 Here is the information for the 2 flights: American Airlines 1719 -- From: Tampa Bay, To: Las Vegas Delta 1854 -- From: Las Vegas, To: Honolulu
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started