Objectives
- Initialize, iterate, and manipulate elements within a 2D array
seats
represents the rows and columns of seats in a theater. Here is the initialization of the array:String[][] seats = {
{"OCCUPIED", "AVAILABLE", "OCCUPIED", "AVAILABLE"},
{"AVAILABLE", "AVAILABLE", "OCCUPIED", "OCCUPIED"},
{"OCCUPIED", "OCCUPIED", "AVAILABLE", "AVAILABLE"}
};
seats
has 3 rows and 4 columns.String
that can either be "AVAILABLE" or "OCCUPIED".displaySeats(String[][] seats)
displaySeats()
method prints out the entire seating arrangement and shows the current status of each seat.Seating Arrangement:
OCCUPIED AVAILABLE OCCUPIED AVAILABLE
AVAILABLE AVAILABLE OCCUPIED OCCUPIED
OCCUPIED OCCUPIED AVAILABLE AVAILABLE
checkSeats(String[][] seats)
checkSeats()
method checks and displays the number of available seats in each row and the total number of available seats in the entire theater.Row 1 has 2 available seats.
Row 2 has 2 available seats.
Row 3 has 2 available seats.
Total available seats: 6
reserveSeat(String[][] seats, int row, int seat)
reserveSeat()
method allows the user to reserve a seat by specifying the row and seat index.[SUCCESS] Seat 0, 1 has now been reserved.
[ERROR] Seat 0, 2 has already been occupied.
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