THINK FIRST·CODE LATER

← All labs

Cinema seat booking with a 2D array

Problem

A small cinema has 5 rows (A–E) of 8 seats. Write CinemaSeats using a boolean[][]. Read booking requests such as B 4 until the word END; for each print B4: booked, B4: already taken or F9: no such seat. Then print the seat map, the number sold and the row with the most free seats (the first one on a tie):

   12345678
A  ........
B  ...X....
C  ..XX....
D  ........
E  .......X
Sold: 4 of 40
Emptiest row: A (8 free)

Use named constants ROWS and SEATS and a method printMap(boolean[][] taken).

Data for this lab

Your program reads its data from standard input. Download the file, then give it to your program as shown below. Start with data set 1: its expected output is given.

l9-5-data-1.txt

B 4
C 3
C 4
E 8
END
What your program must print for l9-5-data-1.txt
B4: booked
C3: booked
C4: booked
E8: booked
   12345678
A  ........
B  ...X....
C  ..XX....
D  ........
E  .......X
Sold: 4 of 40
Emptiest row: A (8 free)

Run your program first, then open this and compare line by line: your output must contain these lines exactly.

How to give the file to my program

Terminal (macOS, Linux, or Windows Command Prompt), after compiling:

java Main < l9-5-data-1.txt

Windows PowerShell does not understand <:

Get-Content l9-5-data-1.txt | java Main

IntelliJ IDEA: Run → Edit Configurations → Redirect input from. Or simply paste the content of the file into the console when the program waits for input.

Write it here or in your IDE, then paste it. Compile and test it yourself before comparing. Your code stays in your browser — it is never sent to or stored on the server.