Initialize, iterate, and manipulate elements within a 2D array
Subsection13.2.1Overview
This Java program simulates a reservation system for movie theater seats using a multidimensional array. It is designed to manage the seats in a theater and it allows the user to check the availability of seats, reserve specific seats, and display the seating layout.
Subsection13.2.22D Array
The 2D array seats represents the rows and columns of seats in a theater. Here is the initialization of the array:
Rows are indexed from 0 to 2 and columns within each row are indexed from 0 to 3.
Each element in the array is a String that can either be "AVAILABLE" or "OCCUPIED".
Subsection13.2.3Instructions
Implement displaySeats(String[][] seats)
The displaySeats() method prints out the entire seating arrangement and shows the current status of each seat.
Example output:
Seating Arrangement:
OCCUPIED AVAILABLE OCCUPIED AVAILABLE
AVAILABLE AVAILABLE OCCUPIED OCCUPIED
OCCUPIED OCCUPIED AVAILABLE AVAILABLE
Implement checkSeats(String[][] seats)
The checkSeats() method checks and displays the number of available seats in each row and the total number of available seats in the entire theater.
It iterates through each row and each seat within the row to count the number of "AVAILABLE" seats.
Example output:
Row 1 has 2 available seats.
Row 2 has 2 available seats.
Row 3 has 2 available seats.
Total available seats: 6
Implement reserveSeat(String[][] seats, int row, int seat)
The reserveSeat() method allows the user to reserve a seat by specifying the row and seat index.
If the seat is available, it changes the seat status to "OCCUPIED" and prints a success message.
If the seat is already occupied, it prints an error message.
Example output:
[SUCCESS] Seat 0, 1 has now been reserved.
[ERROR] Seat 0, 2 has already been occupied.
The expected output is:
Seating Arrangement:
OCCUPIED AVAILABLE OCCUPIED AVAILABLE
AVAILABLE AVAILABLE OCCUPIED OCCUPIED
OCCUPIED OCCUPIED AVAILABLE AVAILABLE
Row 1 has 2 available seats.
Row 2 has 2 available seats.
Row 3 has 2 available seats.
Total available seats: 6
[SUCCESS] Seat 0, 1 has now been reserved.
[ERROR] Seat 0, 2 has already been occupied.
[SUCCESS] Seat 1, 0 has now been reserved.
[SUCCESS] Seat 2, 3 has now been reserved.
Seating Arrangement:
OCCUPIED OCCUPIED OCCUPIED AVAILABLE
OCCUPIED AVAILABLE OCCUPIED OCCUPIED
OCCUPIED OCCUPIED AVAILABLE OCCUPIED
Row 1 has 1 available seats.
Row 2 has 1 available seats.
Row 3 has 1 available seats.
Total available seats: 3
[SUCCESS] Seat 1, 1 has now been reserved.
[SUCCESS] Seat 2, 2 has now been reserved.
Seating Arrangement:
OCCUPIED OCCUPIED OCCUPIED AVAILABLE
OCCUPIED OCCUPIED OCCUPIED OCCUPIED
OCCUPIED OCCUPIED OCCUPIED OCCUPIED
Row 1 has 1 available seats.
Row 2 has 0 available seats.
Row 3 has 0 available seats.
Total available seats: 1