import java.util.Scanner;
public class AirplaneSeating {
private static final int NUM_ROWS = 13;
private static final int SEATS_PER_ROW = 6;
private static final int FIRST_CLASS_ROWS = 2;
private static final int BUSINESS_CLASS_ROWS = 5;
private static final int ECONOMY_CLASS_ROWS = 6;
private static final char AVAILABLE_SEAT = '*';
private static final char ASSIGNED_SEAT = 'X';
private static char[][] seatingPlan = new char[NUM_ROWS][SEATS_PER_ROW];
public static void main(String[] args) {
initializeSeatingPlan();
Scanner scanner = new Scanner(System.in);
boolean quit = false;
while (!quit) {
System.out.println("Please select a ticket type:");
System.out.println("1. First class");
System.out.println("2. Business class");
System.out.println("3. Economy class");
System.out.println("4. Quit");
int choice = scanner.nextInt();
switch (choice) {
case 1:
assignSeat("First class", 0, FIRST_CLASS_ROWS);
break;
case 2:
assignSeat("Business class", FIRST_CLASS_ROWS, BUSINESS_CLASS_ROWS);
break;
case 3:
assignSeat("Economy class", FIRST_CLASS_ROWS + BUSINESS_CLASS_ROWS, ECONOMY_CLASS_ROWS);
break;
case 4:
quit = true;
break;
default:
System.out.println("Invalid choice. Please try again.");
break;
}
}
}
private static void initializeSeatingPlan() {
for (int i = 0; i < NUM_ROWS; i++) {
for (int j = 0; j < SEATS_PER_ROW; j++) {
seatingPlan[i][j] = AVAILABLE_SEAT;
}
}
}
private static void assignSeat(String ticketType, int startRow, int numRows) {
Scanner scanner = new Scanner(System.in);
System.out.println("You have selected " + ticketType + ". Please select a seat (e.g. 1A):");
String seat = scanner.nextLine().toUpperCase();
int row = Integer.parseInt(seat.substring(0, seat.length() - 1)) - 1;
int col = seat.charAt(seat.length() - 1) - 'A';
if (row >= startRow && row < startRow + numRows && col >= 0 && col < SEATS_PER_ROW) {
if (seatingPlan[row][col] == AVAILABLE_SEAT) {
seatingPlan[row][col] = ASSIGNED_SEAT;
System.out.println("Seat " + seat + " has been assigned.");
printSeatingPlan();
} else {
System.out.println("Seat " + seat + " has already been assigned.");
}
} else {
System.out.println("Invalid seat selection.");
}
}
private static void printSeatingPlan() {
System.out.println(" A B C D E F");
for (int i = 0; i < NUM_ROWS; i++) {
System.out.print((i + 1) + " ");
for (int j = 0; j < SEATS_PER_ROW; j++) {
System.out.print(seatingPlan[i][j] + " ");
}
System.out.println();
}
System.out.println();
}
}