Skip to main content

Section 13.2 Growth Level

Multidimensional Arrays

Subsection 13.2.1 Overview

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.

Subsection 13.2.2 2D Array

The 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"}
};
  • The array seats has 3 rows and 4 columns.
  • 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".

Subsection 13.2.3 Instructions

  1. 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
      
  2. 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
      
  3. 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
You have attempted of activities on this page.