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

Auditorium Seat Booking System Code

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)
10 views4 pages

Auditorium Seat Booking System Code

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

import [Link].

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([Link]);

initializeSeats();

while (true) {

displaySeats();

[Link]("Enter seat (e.g., A10) to book or 'exit' to stop:");

String input = [Link]().trim().toUpperCase();

if ([Link]("EXIT")) break;

if (!isValidInput(input)) {

[Link]("Invalid input. Try again (e.g., A10 or D2).");

continue;

int row = [Link](0) - 'A';

int col = [Link]([Link](1)) - 1;


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

[Link]("Seat is already booked. Choose another.");

} else {

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

[Link]("Success! Seat " + input + " has been booked for the meeting.");

displaySeats();

[Link]();

static void initializeSeats() {

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

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

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

static void displaySeats() {

[Link]("\nInitial auditorium status\n");

[Link](" ");

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


[Link]("%3d", i);

[Link]();

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

[Link]((char) ('A' + i) + " ");

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

[Link]("%3c", seats[i][j]);

[Link]();

int total = ROWS * COLS;

int booked = countBookedSeats();

int available = total - booked;

[Link]("\n(N) = Not Available, (Y) = Available");

[Link]("Total Seats: " + total);

[Link]("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 ([Link]() < 2 || [Link]() > 3)

return false;

char rowChar = [Link](0);

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

return false;

try {

int col = [Link]([Link](1));

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

} catch (NumberFormatException e) {

return false;

Common questions

Powered by AI

The initializeSeats method sets all seats in the 2D array to 'Y', marking them as available at the start of the application. This setup is critical for ensuring that the system has a known state from which to operate, preventing any erroneous assumptions about seat availability and ensuring that booking logic functions correctly from the start .

A potential limitation of the current booking logic is the lack of concurrency control, which could lead to race conditions in a multi-threaded environment or web application. With a single-threaded, console-based approach, two users could attempt to book the same seat simultaneously without real-time updates. Additionally, usability is limited to text-based input without a graphical interface, which might restrict ease of use for some users .

The system uses the displaySeats method to show seating availability. It prints a header bar with column numbers followed by each row, indicated by a letter from 'A' to 'J'. Each seat is marked as 'Y' for available or 'N' for booked. The total seats, booked seats, and available seats are calculated and displayed as additional information, providing a comprehensive overview of the current seating layout .

The seat booking system could enhance user experience by integrating a graphical interface, making seat selection more intuitive. Color-coding seats as available or reserved and enabling click-based selection would reduce reliance on text input. Additionally, real-time seat selection previews and confirmation dialogs before final booking could improve interaction. An option to book multiple seats in one transaction and immediate feedback on seat availability could further improve the user engagement and overall experience .

The AuditoriumBookingSystem validates seat input through the isValidInput method. This method checks if the input length is between 2 and 3 characters, ensuring the first character is a letter between 'A' and 'J', and the subsequent characters form a valid integer between 1 and 15. By enforcing these checks, the system avoids errors due to invalid input and enhances reliability by only processing legitimate seat coordinates .

When a user tries to book an already reserved seat, the system checks the seat status in the 2D array. If the seat is marked 'N', indicating it is booked, the system informs the user with a prompt to choose another seat. This approach prevents double-booking, maintains data integrity, and ensures fairness in seat allocation .

The system continuously informs users of the current seating status by repeatedly calling displaySeats each time a booking is attempted or completed. This method updates the displayed seating arrangement, showing which seats are available ('Y') or booked ('N'). It also provides statistics on total, booked, and available seats, ensuring users have all necessary information to make seat reservations efficiently .

The system exemplifies good programming practices by using constants like ROWS and COLS to define array dimensions, which aids in code readability and refactoring. Furthermore, it encapsulates functionality within methods like initializeSeats, displaySeats, and countBookedSeats, promoting modularity and reusability. This organization enhances maintainability and allows for easier updates and debugging .

The design of the AuditoriumBookingSystem prioritizes scalability by organizing seats in a 2D array, enabling easy expansion by adjusting the ROWS and COLS constants. For user experience, the system offers a simple textual interface, uses clear prompts for input, and provides immediate feedback about the success or failure of booking attempts. Furthermore, the system displays a visual representation of the seating arrangement, aiding users in making informed decisions .

The code converts a seat's column number from the input string to an array index by parsing the substring starting from the second character, converting it to an integer, and subtracting one. This zero-based index conversion aligns the user-friendly seat numbering with the array's index structure and prevents off-by-one errors, hence ensuring proper seat access within the array bounds .

You might also like