Question: Create a class called Reservation according to the UML diagram to make a reservation on a flight. The seat preference will consist of a row

Create a class called Reservation according to the UML diagram to make a reservation on a flight. The seat preference will consist of a row number and seat letter (assume 21 rows and seats A, B, C and D). (Use Java code)

Reservation

- seats: int [21][4]

- PassengerName: String

- ID : int

- flightNumber : String

- row: int

- seat: int (translate A to 0, B to 1, C to 2, D to 3)

+ Reservation (name : String , id : int, flight : String, requestedRow: int, requestedSeat: char)

+setRow(int : requestedRow) : void

+ setSeat(char : requestedSeat) : void

+ checkSeatAvailability (): boolean

+ makeReservation() : void

+ toString() : String

Attributes:

seatsa 2-dimensional array of "length" rows and "width" columns , assume that this is [21][4],

passengerName the name of the passenger

id : the id number of the passenger , assume that it cannot be zero

flightNumberthe name or flight number of the plane

rowthe passengers preference seat between 21 rows

seat - the passengers preference seat between 4 columns (A to D)

Methods:

Reservation - the constructor. It will allocate memory for the flight number, passengers name and id, and seating preferences of the passenger.

setRow it assigns its parameter value to the class field row

setSeat - it assigns its parameter value to the class field seat

checkSeatAvailability this method accepts the passengers seating preferences and returns false if the seat is already taken, otherwise returns true.

How to :

When the 2d array is created, the value of all array member will be zero as default, after the user enter the preferences, you need to check that array members value is zero or not. If it is zero, it means that the seat is available. In order to assign the seat to the passenger, assign the passengers id to this seat, so that it show that the seat is taken

makeReservation - this method designs to assign a seat for the passenger. If the seat is available, the seat will mark sold seats by changing its value from 0 to the passengers id.

toString() : It displays the final reservation information that includes the passengers name and id, the flight number, and the passenger's seat assignment

The Reservation class attempts to place a reservation on one flight.

Write an application program to test Reservation class. If the reservation is made successful, it should print the flight information, passengers name and id, and passengers seat assignment (hint: toString() method); if the seat is already taken by another passenger ,then print the message the seat is not available, do you want to continue to reserve an available seat .

After the passenger makes the reservation, then asks the passenger if there is any companion with his/her and if another reservation is needed for the companion, then ask for the ID of this person, then check the seat availability and print the result.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock 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 Databases Questions!