Skills to be Applied

In addition to what has been covered in previous assignments, the use of the following items, discussed in class, will probably be needed:

Classes
Instance Objects
Accessors/Mutators(Modifiers) methods
Visibility Modifiers (Access specifier) - public, private, etc.
Encapsulation concept
Aggregation relationship between classes

Program Description

Class Diagram: see image.

Assignment #4 will be the construction of 2 new classes and a driver program (the class containing a main method).

Schedule class

The Schedule class describes information of departure or arrival of a flight. It has following attributes:

Attribute name, Attribute type, Description
city, String, The city of departure or arrival
date, String, The date of departure or arrival
time, String, The time of departure or arrival

The following constructor should be provided to initialize each attribute. This constructor initializes the value of city, date, and time to "?".

public Schedule( )

The following accessor methods should be provided to get the attributes:

public String getCity()
public String getDate()
public String getTime()

The following modifier(mutator) methods should be provided to set the attributes: public void setCity(String someCity)

public void setDate(String someDate)
public void setTime(String someTime)

The following method must be defined:

public String toString()

toString method should return a string of the following format:

PHX,01-12-17,7:00am

where "PHX" is a city, "01-12-17" is date, and "7:00am" is time. So you need to insert "," between these three variables.

Note that you can choose a meaningful parameter variable name for each method.

Flight class

The Flight class describes a flight that a passenger can take. It has the following attributes:

Attribute name, Attribute type, Description
airlines, String, The airlines of the flight.
flightNum, int, The flight number
departure, Schedule, The departure of the flight
arrival, Schedule, The arrival of the flight

The following constructor should be provided to initialize each attribute. This constructor initializes the value of airlines to "?" and the value of flightNum to 0, and the value of city, date, and time to ? by instantiating two objects of Schedule using the constructor of the Schedule class

public Flight( )

The following accessor methods should be provided to get the attributes:

public String getAirlines()
public int getFlightNum()
public Schedule getDeparture()
public Schedule getArrival()

The following modifier(mutator) methods should be provided to change the attributes:

public void setAirlines(String airlinesName)
 public void setFlightNum(int number)
public void setDeparture(String someCity, String someTime, String someDate)
public void setArrival(String someCity, String someTime, String someDate)

The following method must be defined:

public String toString()

The toString() method constructs a string of the following format:

\nAirlines:\tAA\n
Number:\t\t102\n
Departure:\tPHX,01-12-05,7:00am\n
Arrival:\tSFO,01-12-05,9:00am\n\n

Assignment4

(Note that this part is already done in the Assignment4.java file that is given to you. This explains each functionality of this class.)

In this assignment, download Assignment4.java file by clicking the link, and use it for your assignment. You do not need to modify Assignment4.java file. You only need to write Flight.java and Schedule.java files.

The following is the description of Assignment4 class.

The driver program will allow the user to interact with your other class modules. The purpose of this module is to handle all user input and screen output. The main method should start by displaying the following menu in this exact format:

Choice\t\tAction\n
------\t\t------\n
A\t\tAdd Flight\n
D\t\tDisplay Flight\n
Q\t\tQuit\n
?\t\tDisplay Help\n\n

Next, the following prompt should be displayed:

What action would you like to perform?\n

Read in the user input and execute the appropriate command. After the execution of each command, re-display the prompt. Commands should be accepted in both lowercase and uppercase.

Add Flight

Your program should display the following prompt:

Please enter the flight information:\n
Enter its airlines name:\n

Read in the user input and set the airlines name on the flight object. Then the following prompt:

Enter its flight number:\n

Read in the user input and set the flight number on the flight object. Then the following prompt:

Enter its departure city:\n

Read in the user input. Then the following prompt:

Enter its departure time:\n

Read in the user input. Then the following prompt:

Enter its departure date:\n

Read in the user input and set the departure city, time and date on the flight object. Then the following prompt:

Enter its arrival city:\n

Read in the user input. Then the following prompt:

Enter its arrival time:\n

Read in the user input. Then the following prompt:

Enter its arrival date:\n

Read in the user input and set the arrival city, time and date on the flight object.

Note that there is only one Flight object in this assignment. Thus when "Add Flight" option is selected more than once, the new one overwrites the old Flight object information.

Display Flight

Your program should display the flight information in the following format:

\nAirlines:\tAA\n
Number:\t\t102n
Departure:\tPHX,01-12-05,7:00am\n
Arrival:\tSFO,01-12-05,9:00am\n\n

Make use of the toString method of the Flight class to display this information. The toString method is used together with System.out.print method.

(System.out is NOT to be used within the toString method.)

Quit

Your program should stop executing and output nothing.

Display Help

Your program should redisplay the "choice action" menu.

Invalid Command

If an invalid command is entered, display the following line:

Unknown action\n

Error Handling

Your program is expected to be robust to handle all test cases.

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.