Question
Java 1.) Create a Passenger class according to the UML diagram. Each object of the class stores a passengers name and his/her seating preference. -
Java
1.) Create a Passenger class according to the UML diagram. Each object of the class stores a passengers name and his/her seating preference.
- name:String - row:int - seatCode:int (Translate seat code A to seat number 0, B to 1, C to 2, and D to 3) |
Passenger(passengerName:String, requestedRow:int, requestedSeat:char) + setName(passengerName:String) + setRow(requestedRow:int) + setSeatCode(requestedSeat:char) + getName():String + getRow():int + getSeatCode():char |
2.) Write a reservation program (LastNameFirstNameReservations.java), a driver class, that uses sentinel loop which repeatedly
-accepts a passengers name, and his/her seating preference (The preference consists of a row number and a seat letter. Assume that there are 21 rows and four seats, A, B, C and D.)
-adds the passenger to a list. Create the list, passengerList, using ArrayList class. (When adding, search the list of passengers for a matching name. If he/she is already in the list, update his/her new seating preference; otherwise, create a new passenger object and add it to the end of the list.)
Question 2. Part 2 : Check Seat Availability
3.) Create a class named Plane according to the UML diagram.
Plane |
- seats:int[][] |
+ Plane(rows:int, cols:int) + makeReservation(passengerID:int, passengerRequesting:Passenger): boolean + getID(setRow:int, seatCode:char): int + getSeatAssignment(passengerID:int): String |
Fields:
- seats a 2-dimensional array (Part 1 assumed seats[21][4], but you can make Plane more flexible by using the values of the parameters variables, rows and cols).
Constructor:
- Plane(rows,cols) the constructor. It declares the array, seats, and initializes each element of the array with an illegal ID (e.g., -1) to represent an empty seat.
Methods:
- makeReservation(id, request)this method accesses seats to determine whether the preferred/requested seat by passengerRequesting is already taken by somebody else or not. If not, record the passengerID at that position in seats. Return true if you make the reservation successfully, otherwise false. Here, passengerID should be the index number of passengerList which you created at Part 1.
- getID(seatRow,seatCode)return the value at that position in the array seats
- getSeatAssignment(passengerID)search by rows and columns until you find a matching ID in seats, then convert the row and column into a string (e.g., if seats[5][2] == passengerID is true, then the method should return "6C".)
4.)Modify your reservation program, the driver class (LastNameFirstNameReservations.java) as follows:
1. Create a Plane object.
(We assume that your driver class makes reservations on this one plane.)
2. For each passenger (from Part 1):
Make place a reservation with his/her seat preference.
If a reservation is made successful, it displays the passenger's seat assignment; otherwise, report seat unavailable.
3. Once the sentinel loop terminates (from Part 1), it displays 2D table showing the elements in seats array of the Plane object.
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