Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please solve Java Program with photo, and I will give u my voice Description program: A hotel has 40 rooms, arranged in 10 floors as

Please solve Java Program with photo, and I will give u my voice Description program: A hotel has 40 rooms, arranged in 10 floors as follows:

1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
17 18 19 20
21 22 23 24
25 26 27 28
29 30 31 32
33 34 35 36
37 38 39 40

This room arrangement is mapped, row-wise, to a 1D-array of size 40 as follows:

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 ..

Implement a well-structured Java program to enable a user to reserve and cancel room reservations in the hotel. The program uses Array to store the reservation information: 0 indicates that a room is not reserved, 1 indicates that a room is reserved and 2 indicates that a suite is reserved. Originally all rooms are not reserved:

0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0

Your program starts by initializing a 1D-array. It must then display the following menu: 1. Display number of available rooms. 2. Display room status for all rooms. 3. Reserve a room(s). 4. Cancel reservation(s). 5. Exit. Please select your choice: Your program must loop as long as option 5 has not been selected. It must display an appropriate error message if an invalid choice is entered. Option 1: Display number of available rooms It displays the current number of available rooms. This option must be implemented by reading directly from initialized 1D-array of rooms. If all the rooms are not reserved the output of this option is:

1.Display number of available rooms. 2.Display status of all rooms. 3. Reserve room(s). 4.Cancle reservation(s). 5.Exit. Please select your choice:1 number of available rooms=40 If five rooms are reserved, for example, room [1], [9], [18], [26] and [37] then the output is:

1.Display number of available rooms. 2.Display status of all rooms. 3. Reserve room(s). 4.Cancle reservation(s). 5.Exit. Please select your choice:1 number of available rooms=35 Option 2: Display room status for all rooms It displays the status of each room. For example, if rooms [1], [9], [18], [26] and [37] are the only reserved rooms then the output is:

1.Display number of available rooms. 2.Display status of all rooms. 3. Reserve room(s). 4.Cancle reservation(s). 5.Exit. Please select your choice:2 (Reserved) (2) (3) (4) (5) (6) (7) (8) (Reserved) (10) (11) (12) (13) (14) (15) (16) (17) (Reserved) (19) (20) (21) (22) (23) (24) (25) (Reserved) (27) (28) (29) (30) (31) (32) (33) (34) (35) (36) (Reserved) (38) (39)(40) Option 3: Reserve room(s) It displays the status of each room. If there are no available rooms, the message: Sorry, there are no available rooms. is displayed:

1.Display number of available rooms. 2.Display status of all rooms. 3. Reserve room(s). 4.Cancle reservation(s). 5.Exit. Please select your choice:3 (Reserved)(Reserved)(Reserved)(Reserved) (Reserved)(Reserved)(Reserved)(Reserved) (Reserved)(Reserved)(Reserved)(Reserved) (Reserved)(Reserved)(Reserved)(Reserved) (Reserved)(Reserved)(Reserved)(Reserved) (Reserved)(Reserved)(Reserved)(Reserved) (Reserved)(Reserved)(Reserved)(Reserved) (Reserved)(Reserved)(Reserved)(Reserved) (Reserved)(Reserved)(Reserved)(Reserved) (Reserved)(Reserved)(Reserved)(Reserved) Sorry, there are no available rooms.

If there are one or more available rooms, it will ask the user to choose one of two choices, first choice is to reserve a normal room and second choice is to reserve a suite which is a whole floor. If the user chooses to reserve a suite and there are no available suits then the message: Error: No available suits. is displayed:

1.Display number of available rooms. 2.Display status of all rooms. 3. Reserve room(s). 4.Cancle reservation(s). 5.Exit. Please select your choice:3 (Reserved) (2) (3) (4) (Reserved) (6) (7) (8) (Reserved) (10) (11) (12) (Reserved) (14) (15) (16) (17) (Reserved) (19) (20) (Reserved) (22) (23) (24) (25) (Reserved) (27) (28) (Reserved) (30) (31) (32) (33) (34) (Reserved) (36) (Reserved) (38) (39) (40) 1.Reserve a room.

2. Reserve a suite. What's your choice: 2 Error: No available suits. 1. If there are available suites to complete the operation then the program prompts for and reads the floor number. 2. If the reservation is successful, the message: Required suite successfully reserved is displayed. 3. If the required suite is already reserved, the message: Error: This suite is already reserved is displayed and read another suite number until reservation succeed. 4. If there are available rooms to complete the operation then the program prompts for and reads the room number. 5. If the reservation is successful, the message: Required room successfully reserved is displayed. 6. If the required room is already reserved, the message: Error: This room is already reserved is displayed and read another suite number until reservation succeed.

Options 4. Cancel reservation(s): It displays the available rooms if any. It asks the user to choose one of two choices, cancel room reservation and cancel suite reservation. If the user chooses to cancel a suite reservation, the program will ask for the floor number. If the floor number is not reserved, then an error message will be displayed Error: This suite is not reserved. If the floor number is reserved, then a message will be displayed to confirm the operation Suite reservation is canceled. If the user chooses to cancel a room reservation, the program will ask for the room number. If the room number whose reservation is going to be deleted is not reserved, the error message: Error: This room is not reserved. Is displayed: If the room number is reserved, then a message will be displayed to confirm the operation Room reservation is canceled. Options 5. Exit It terminates the program.

Note: Your project must not use 2D-arrays or Strings. You must use meaningful variable names and proper indentation in your program.

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

Students also viewed these Databases questions