Question: Instructions Use the following information to create a program for a train reservation system. Your program should contain three separate classes: a Passenger class,

Instructions Use the following information to create a program for a train reservation system. Your program head: Passenger o Page: 1 A dummy node (a blank passenger object that will represent the first passenger in A toString method that prints out the contents of the reservation list. This toString method should also CSC 249 Data Structures and Algorithms Project - 1 (Reservation System) If any of the options chosen would

Instructions Use the following information to create a program for a train reservation system. Your program should contain three separate classes: a Passenger class, a Reservation class, and a Demo class. In this program, the Reservation class will function as a doubly linked list that contains Passenger objects. The Demo class will be used to make modifications to the Reservation list. Passenger Class This class should contain the following fields: name: String phone: String seat: int o This is the seat number assigned cost: int o This is the cost the passenger paid (each seat may have a different price) next: Passenger o This is a reference to the passenger that follows this passenger in the list previous: Passenger o This is a reference to the passenger that precedes this passenger in the list The Passenger class should contain the appropriate getters and setters for these attributes, a no-arg constructor, and a constructor that accepts the following arguments: name, phone, seat and cost. Reservation Class This class will act as our doubly linked list. This class should contain the following attributes: head: Passenger o A dummy node (a blank passenger object that will represent the first passenger in the head: Passenger o Page: 1 A dummy node (a blank passenger object that will represent the first passenger in the reservation list) tail: Passenger o A dummy node (a blank passenger object that will represent the last passenger in the reservation list) size: int o The number of reservations in the reservation list CSC 249 Data Structures and Algorithms Project - 1 (Reservation System) Note: Make sure to review the section in your book on Dummy Nodes - they should help simplify the logic required for methods that operate on the Reservation class. The Reservation class should contain a no-arg constructor which initializes the size, head and tail attributes. This no-arg constructor should also properly connect the head and tail nodes of the doubly linked list. The Reservation class should also contain the following methods: A method that accepts a Passenger object and adds it to the end of the reservation list. A method that accepts two Passenger objects (a new Passenger to be added, and a Passenger that is currently pointed in the reservation list). This method will insert the new Passenger into the reservation list at the position directly after the Passenger that is currently pointed.. A method that accepts a Passenger object, returns nothing, and removes the Passenger from the reservation list. A toString method that prints out the contents of the reservation list. This toString method should also calculate and display the number of passengers in the reservation list, as well as the total cost A toString method that prints out the contents of the reservation list. This toString method should also calculate and display the number of passengers in the reservation list, as well as the total cost paid by the passengers in the list. Demo Class This class will serve to accept user input and manipulate the Reservation doubly linked list. The Demo class should instantiate a Reservation object and display a menu to the user that will allow for the following actions: 1. Add a new passenger to the reservation system 2. Insert a new passenger after the passenger that is currently pointed o If a passenger is being added/inserted to an empty reservation list, that passenger should then be set to be the one that is currently pointed. 3. Print the contents of the reservation list 4. Display the current passenger (including name, phone, seat and cost) o When displaying the current passenger for the first time, the first passenger in the reservation list should be displayed. To accomplish this, create a Passenger reference variable and assign it the first Passenger in the Reservation 5. Cancel the current reservation (meaning that remove the current passenger). o o Display a message that the reservation of that specific passenger is canceled. When removing the current passenger, the new current passenger will be the passenger that directly follows the removed passenger. 6. Skip to the next passenger o If you are at the end of the reservation list, the next Passenger should be the first Passenger in the reservation list. 7. Return to the previous passenger 8. Exit Dogor 2 Validate the user's input for the menu option. The user should be required to enter a valid menu option before advancing. CSC 249 Data Structures and Algorithms Project - 1 (Reservation System) If any of the options chosen would not work due to there being no applicable passengers in the reservation list, an appropriate error message should be displayed. The user should be allowed to repeatedly select menu options until they choose to Exit.

Step by Step Solution

3.44 Rating (154 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Based on the instructions provided we are to create a simple train reservation system consisting of three classes Passenger Reservation and Demo Below is a sample implementation in Java for these clas... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!