[SOLVED] Airplane seat reservation system in java with full source code
In this project, you will implement an airplane seat reservation system. An airplane has two classes of service (first and economy). Each class has a sequence of seat rows. The following figure shows the seat chart of the airplane.
A reservation request has one of two forms. One form is that an individual passenger request consists of the passenger name, a class of service, and a seat preference such as W(indow), C(enter), or A(aisle) seats. The reservation program either finds a matching seat (the search may start from the first row of the class.) and reserves it for the passenger, or it fails if no matching seat is available. (For example, if the user's preference is a W(indow) seat and none is available, tell the user no Window seat is available and ask for another seat preference.) The other form is that a group request consists of a list of passenger names and a class of service. (Groups cannot specify a seat preference). The reservation program finds the first row of adjacent seats in a seat row that is sufficient to accommodate the group, or if no such seat row exists, finds the row with the largest number of adjacent seats in any seat row, fills it up with members of the group, and repeats that process (finding the row with the largest number of adjacent seats) until all members of the group have been seated. If there is insufficient space to seat all members of the group, none should be seated.
A cancellation request consists of the name of one or more passengers. The seats that are occupied by passengers in the request are emptied; passengers in the request that are not seated are ignored. There are two kinds of report: seat availability chart and manifest list. A seat availability chart shows the available seats of each row of each class as shown below. You can guess the rest of the seat availability chart based on the example for the First Class.
A manifest lists the occupied seats and the passengers seated in them: First 1A: John Williams 1C: Harry Hacker 2A: Sarah Michaels 2B: Jonah Arks Economy Your program must be called ReservationSystem. Use a command line argument to read the name of a file that holds information from a prior program run. If the file does not exist, the program creates one. You may use the exists() method of the File class to check.
The following shows how you would run the program on command prompt. java ReservationSystem flightname where flightname is the name of a file that holds information from a prior program run. In Eclipse, follow Run- Run Configurations - Arguments, enter the command line argument, in our case flightname, in the box named Program Arguments, and run the program.
The user interacts with the program to make a reservation, and the user input is read from standard input (System.in). The user interface for this program is as follows. Prompt the user: Add [P]assenger, Add [G]roup, [C]ancel Reservations, Print Seating [A]vailability Chart, Print [M]anifest, [Q]uit
The following describes the function(s) of each option.
Name: John Smith Service Class: First Seat Preference: W
Print the seat number such as 1A on which the passenger has been seated, or Request failed.
member names should be separated by a comma)
Group Name: cssjsu
Names: Venkathan Subramanian,Karl Schulz Service
Class: Economy
Print the seat numbers on which the passengers have been seated, or Request failed.
Names: John Smith
When the user wants to cancel a group reservation, prompt as follows: (bold are user inputs) Group Name: cssjsu
A cancellation of a group reservation will cancel the reservations of all group members. For simplicity, let's assume an individual group member cannot cancel his/her reservation only.
A reservation request has one of two forms. One form is that an individual passenger request consists of the passenger name, a class of service, and a seat preference such as W(indow), C(enter), or A(aisle) seats. The reservation program either finds a matching seat (the search may start from the first row of the class.) and reserves it for the passenger, or it fails if no matching seat is available. (For example, if the user's preference is a W(indow) seat and none is available, tell the user no Window seat is available and ask for another seat preference.) The other form is that a group request consists of a list of passenger names and a class of service. (Groups cannot specify a seat preference). The reservation program finds the first row of adjacent seats in a seat row that is sufficient to accommodate the group, or if no such seat row exists, finds the row with the largest number of adjacent seats in any seat row, fills it up with members of the group, and repeats that process (finding the row with the largest number of adjacent seats) until all members of the group have been seated. If there is insufficient space to seat all members of the group, none should be seated.
A cancellation request consists of the name of one or more passengers. The seats that are occupied by passengers in the request are emptied; passengers in the request that are not seated are ignored. There are two kinds of report: seat availability chart and manifest list. A seat availability chart shows the available seats of each row of each class as shown below. You can guess the rest of the seat availability chart based on the example for the First Class.
Availability List:
First 1: B, D 2: C, D EconomyA manifest lists the occupied seats and the passengers seated in them: First 1A: John Williams 1C: Harry Hacker 2A: Sarah Michaels 2B: Jonah Arks Economy Your program must be called ReservationSystem. Use a command line argument to read the name of a file that holds information from a prior program run. If the file does not exist, the program creates one. You may use the exists() method of the File class to check.
The following shows how you would run the program on command prompt. java ReservationSystem flightname where flightname is the name of a file that holds information from a prior program run. In Eclipse, follow Run- Run Configurations - Arguments, enter the command line argument, in our case flightname, in the box named Program Arguments, and run the program.
The user interacts with the program to make a reservation, and the user input is read from standard input (System.in). The user interface for this program is as follows. Prompt the user: Add [P]assenger, Add [G]roup, [C]ancel Reservations, Print Seating [A]vailability Chart, Print [M]anifest, [Q]uit
The following describes the function(s) of each option.
Add [P]assenger
When the user wants to add a passenger, prompt the user:Name: John Smith Service Class: First Seat Preference: W
Print the seat number such as 1A on which the passenger has been seated, or Request failed.
Add [G]roup
When the user wants to add a group, prompt as follows: (bold are user inputs; the groupmember names should be separated by a comma)
Group Name: cssjsu
Names: Venkathan Subramanian,Karl Schulz Service
Class: Economy
Print the seat numbers on which the passengers have been seated, or Request failed.
[C]ancel Reservations
First prompt the user asking if the cancellation is for an individual or a group. When the user wants to cancel an individual reservation (as opposed to a group reservation), prompt as follows:Names: John Smith
When the user wants to cancel a group reservation, prompt as follows: (bold are user inputs) Group Name: cssjsu
A cancellation of a group reservation will cancel the reservations of all group members. For simplicity, let's assume an individual group member cannot cancel his/her reservation only.
Comments
Post a Comment