I am working on a simple reservation system with 10 elements (places). I want to check if the elements are installed from 1 to 5. If "Yes", then install the elements from 6 to 10 ("Vice-Versa").
An element is not assigned a value more than once. My code is still.
boolean[] seats = new boolean[10];
Scanner input = new Scanner(System.in);
System.out.print("Choose FirstClass(1) / Economy(2): ");
int flightClass = input.nextInt();
for (int j = 0; j < seats.length; j++) {
System.out.println("\nEnter Seat Number: ");
int enterSeat = input.nextInt();
if (flightClass == 1) {
if (enterSeat >= 0 && enterSeat <= 5) {
System.out.println("You're in the First Class.");
seats[enterSeat] = true;
System.out.printf("You're Seat Number is %d\n", enterSeat);
}
} else if (flightClass == 2) {
if (enterSeat >= 6 && enterSeat <= 10) {
System.out.println("You're in the Economy.");
seats[enterSeat] = true;
System.out.printf("You're Seat Number is %d\n", enterSeat);
}
}
My question is: how to check if elements from 1 to 5 are installed, and if they are, install elements from 6 to 10 and vice versa?
For instance:
Enter a seat number. book: 1
Enter a seat number. book: 2
Enter a seat number. book: 3
Enter a seat number. book: 4
Enter a seat number. book: 5
All first class seats (1-5) are installed. Now the remaining places are from 6 to 10.
Enter a seat number. book: 6 so on ...