Careeroza
Real World Example
Cinema Seat Booking
Movie booking apps like BookMyShow keep a seat map that is essentially a 2D array: rows A, B, C... and seat numbers. Booking a seat changes one cell; the screen redraws the grid.
Example
import java.util.Arrays;
public class Main {
public static void main(String[] args) {
char[][] hall = new char[4][6];
for (char[] row : hall) Arrays.fill(row, 'O'); // O = available
int[][] bookings = {{0, 2}, {0, 3}, {2, 0}, {2, 1}, {2, 2}, {3, 5}};
for (int[] b : bookings) {
hall[b[0]][b[1]] = 'X'; // X = booked
}
System.out.println(" 1 2 3 4 5 6 [SCREEN]");
int free = 0;
for (int r = 0; r < hall.length; r++) {
System.out.print((char) ('A' + r) + " ");
for (char seat : hall[r]) {
System.out.print(seat + " ");
if (seat == 'O') free++;
}
System.out.println();
}
int ticketPrice = 180;
System.out.println("Booked: " + bookings.length + ", Free: " + free);
System.out.println("Revenue so far: Rs. " + bookings.length * ticketPrice);
}
}Output
1 2 3 4 5 6 [SCREEN] A O O X X O O B O O O O O O C X X X O O O D O O O O O X Booked: 6, Free: 18 Revenue so far: Rs. 1080