Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

NEED JAVA HELP! Task: Create a basic flight reservation program The local airport would like to display flight information for all flights that occur each

NEED JAVA HELP!

Task: Create a basic flight reservation program

The local airport would like to display flight information for all flights that occur each day. Flight information includes the data about each flight (its destination, origin, arrival time, etc) as well as the reservations made for that flight. They keep this information in two [very disorganized] text files - your program will sort out the data and display it to the user.

Getting Started

Your application will consist of 5 Java classes:

Lab3.java

Flight.java

CommercialFlight.java

PrivateFlight.java

Reservation.java

It will read in data from two text files: flight-schedule.txt and reservations.txt. You will place these files at the top of your project in Eclipse - that is, not within the source folder or any other folder. If this is done correctly, within your code, you will need only refer to the file name, rather than giving a full path to the location of each file.

Lab3.java

This class will run your program (Hint: it must have a main method). The main method will have an ArrayList of flight - it will populate the data for these flights and their reservations from the text file (see below for additional details).

Flights

Flights have a flight number, an origin airport, a destination airport, a departure time, an arrival time, and a collection of reservations. Flight.java must implement the Comparable interface. Flights are comparable based upon their departure time. This class must have a toString method as well as getters and setters (and adders, as applicable) for all class variables. All Flight classes must have 1 constructor, which take the following parameters in order: flight number, origin, destination, departure, arrival. Your program will handle two types of flights: commercial and private. You will create two subclasses to handle this relationship. The Flight class should have a method isCommercialFlight() which returns true if the instance of the flight is a CommercialFlight.

Data for each flight is stored in flight-schedule.txt in the following format:

772,commercial,ABC,XYZ,14:06,17:33

Where this denotes flight 777 is a commercial flight originating at airport ABC, destination airport XYZ. Its departure time is 14:05 and arrival time is 17:33. Each line in the file is formatted in this way, so each line represents a different flight.

Flight.java will have a class method parseFlightInformation which takes a String parameter, a single line of text in the format above. This method will return a type of Flight object populated from the data in the given parameter.

Reservations

Reservations have a reservation number, a flight number, a first name and last name for the passenger, and a seat number. The reservation number is the flight number concatenated with the seat number - that is, if the flight number is 555 and the seat number is 22, the reservation number will be 55522. Reservation.java must implement the Comparable interface. Reservations are comparable based upon their seat number. This class must have a toString method as well as getters and setters for all class variables. This class must have 1 constructor which takes the following parameters in order: reservation number, flight number, last name, first name, seat number.

Data for each reservation is stored in reservations.txt in the following format:

772,Doe,Jane,55

Where this denotes a reservation for flight 777 for Jane Doe (first name: Jane, last name: Doe) in seat 55. The reservation number would then be 77255.

Reservation.java will have a class method parseReservationInformation which takes a String parameter, a single line of text in the format above. This method will return a new Reservation object populated with the data in that String.

Textfiles:

flight-schedule.txt

866,commercial,SAT,LAS,13:05,14:00 815,commercial,SAT,LAS,08:00,09:05 267,private,SAT,SLC,05:50,09:50 896,commercial,SAT,JFK,07:00,11:50

reservations.txt.

815,Reyes,Hugo,22 815,Reyes,Carmen,23 815,Reyes,Diego,21 815,Reyes,David,20 896,Goodspeed,Horace,9 866,Littleton,Claire,2 866,Locke,John,101 866,Ford,James,4 267,Hume,Desmond,1 267,Pace,Charlie,3 815,Kwon,Jin-Soo,2 815,Shephard,Jack,132 896,Dawson,Michael,24 896,Burke,Juliet,35 815,Straume,Miles,47 267,Kwon,Sun-Hwa,6 267,Jarrah,Sayid,8 815,Linus,Benjamin,118 896,Linus,Roger,118 866,Alpert,Richard,120 866,Rutherford,Shannon,15 896,Nadler,Rose,57 896,Carlyle,Boon,37 896,Nadler,Bernard,58 866,Rousseau,Alexandra,13 866,Friendly,Tom,6 866,Shephard,Christian,14 896,Hawking,Eloise,47 866,Widmore,Charles,103 866,Chang,Pierre,115 896,Reyes,Carmen,22 815,Smith,Elizabeth,67 866,Fernandez,Nikki,89 896,Pace,Liam,135 815,Widmore,Penelope,92 815,Rom,Ethan,99 866,Keamy,Martin,111 896,Chandler,Cindy,88 896,Arzt,Leslie,42

OUTPUT:

The first section of output is a listing of all flights, in order of departure. This should be generated using the toString method in the Flight class (note that the toString method itself should never print). The second section of output is a listing of all reservations on flight 815, in order of seat number. Again, leverage the toString method in the Reservation class.

The main method will handle the file reading, and call methods in Flight and Reservation classes to do the parsing. Handle any errors that could occur when reading from these files.

image text in transcribed

When nn, your program will read in the data from the given text files, and print exactly as follows: Private Flight 267 from SAT to SLC departs: 05:50 arrives: 09:50. Seats reserved: 4 Commercial Flight 896 from SAT to JFK departs: 07:00 arrives: 11:50. Seats reserved: 12 Commercial Flight 815 from SAT to LAS departs: 08:00 arrives: 09:05. Seats reserved: 11 Commercial Flight 866 from SAT to LAS departs: 13:05 arrives: 14:00. Seats reserved: 12 Flight 815 (2) Kwon, Jin-Soo Flight 815 (20) Reyes, David Flight 815 (21) Reyes, Diego Flight 815 (22) Reyes, Hugo Flight 815 (23) Reyes, Carmen Flight 815 (47) Straume, Miles Flight 815 (67) Smith, Elizabeth Flight 815 (92) Widmore, Penelope Flight 815 (99) Rom, Ethan Flight 815 (118) Linus, Benjamin Flight 815 (132) Shephard, Jack

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Main Memory Database Systems

Authors: Frans Faerber, Alfons Kemper, Per-Åke Alfons

1st Edition

1680833243, 978-1680833249

More Books

Students also viewed these Databases questions