Write a Java application as a small airline reservation system. The system has o
ID: 3695258 • Letter: W
Question
Write a Java application as a small airline reservation system. The system has only one airplane with 10 seats: 1 to 5 for First Class and 6 to 10 for Economy.
The system prompts the user to type 1 for First Class or 2 for Economy.
If the user chooses the First Class, a currently availabe First Class seat is printed in the boarding pass.
If the user chooses the Economy, a currently available Economy seat is printed in the boarding pass.
If the user's choice of seat class is no available, your program should ask if the user is OK with the other seat class.
If the user is OK to switch the seat class, you try to reserver again. If successful, print the boarding pass of the assigned seat.
Otherwise, print the message "Next flight leaves in 3 hours"
The program runs forever. It will be enhanced to exit when the whole airplane is full, for extra credit.
The Console Output
Programmer Notes
This is Exercise 7.19. Write and document your program per class coding conventions. Name your class as Assign7.
In your class create an array private static boolean seats[] = new boolean[11]; Each element represents a seat. It's index is the seat number (0 is never used). It's value false means available, and true means reserved.
Write a method public static int reserve(boolean isFirstClass). The argument is true for First Class and false for Economy. The method will search the range of the array and reserve a seat if one is available. Return the seat number. When no seat is available in the specified range, return -1.
In the main method write an infinite loop while(true){...}
In the loop body, print the prompt and read the next int, check its value to set variable boolean isFirstClass;
call reserve(isFirstClass). If the return value is -1, prompt the user if OK to switch.
When confirmed, set isFirstClass = !isFirstClass, and then call reserve(isFirstClass) again.
Depending on its returned value, print the boarding pass or the message "Next flight leaves in 3 hours".