[go: up one dir, main page]

0% found this document useful (0 votes)
7 views4 pages

Java

Uploaded by

ashutoshdash.p
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views4 pages

Java

Uploaded by

ashutoshdash.p
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

import java.util.

Scanner;

public class AuditoriumBookingSystem {

static final int ROWS = 10;

static final int COLS = 15;

static char[][] seats = new char[ROWS][COLS];

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

initializeSeats();

while (true) {

displaySeats();

System.out.println("Enter seat (e.g., A10) to book or 'exit' to stop:");

String input = sc.nextLine().trim().toUpperCase();

if (input.equals("EXIT")) break;

if (!isValidInput(input)) {

System.out.println("Invalid input. Try again (e.g., A10 or D2).");

continue;

int row = input.charAt(0) - 'A';

int col = Integer.parseInt(input.substring(1)) - 1;


if (seats[row][col] == 'N') {

System.out.println("Seat is already booked. Choose another.");

} else {

seats[row][col] = 'N';

System.out.println("Success! Seat " + input + " has been booked for the meeting.");

displaySeats();

sc.close();

static void initializeSeats() {

for (int i = 0; i < ROWS; i++) {

for (int j = 0; j < COLS; j++) {

seats[i][j] = 'Y';

static void displaySeats() {

System.out.println("\nInitial auditorium status\n");

System.out.print(" ");

for (int i = 1; i <= COLS; i++) {


System.out.printf("%3d", i);

System.out.println();

for (int i = 0; i < ROWS; i++) {

System.out.print((char) ('A' + i) + " ");

for (int j = 0; j < COLS; j++) {

System.out.printf("%3c", seats[i][j]);

System.out.println();

int total = ROWS * COLS;

int booked = countBookedSeats();

int available = total - booked;

System.out.println("\n(N) = Not Available, (Y) = Available");

System.out.println("Total Seats: " + total);

System.out.println("Available Seats: " + available);

static int countBookedSeats() {

int count = 0;

for (char[] row : seats) {

for (char seat : row) {

if (seat == 'N') count++;


}

return count;

static boolean isValidInput(String input) {

if (input.length() < 2 || input.length() > 3)

return false;

char rowChar = input.charAt(0);

if (rowChar < 'A' || rowChar > 'J')

return false;

try {

int col = Integer.parseInt(input.substring(1));

return col >= 1 && col <= 15;

} catch (NumberFormatException e) {

return false;

You might also like