Question: Change the program AirlineDriver.java to assign passenger seats in an airplane. public class AirlineDriver { public static void main (String[] args) { char [][] layout
Change the program AirlineDriver.java to assign passenger seats in an airplane.
public class AirlineDriver { public static void main (String[] args) { char [][] layout = { {'A', 'B','C','D'}, {'A', 'B','C','D'}, {'A', 'B','C','D'}, {'A', 'B','C','D'}, {'A', 'B','C','D'}}; displaySeats(layout); } public static void displaySeats(char [][] plane) { for (int row = 0; row < plane.length; row++) { System.out.print(" " + (row + 1) + " "); // add for loop to display one row // display row System.out.println(); } } } Chesapeake Airlines is a small commuter airline with seats for 20 passengers in 5 rows of 4 seats each. Here is the layout:
1 A B C D
2 A B C D
3 A B C D
4 A B C D
5 A B C D
The user enters the row (1 5) and the seat (A D). The seat entry may be lowercase.
Use this code to enter the seat:
System.out.print(" Enter row and seat ");
seat = scan.nextLine();
r = seat.??
c = seat.??
What will you need to do to change r to a valid row index?
What will you need to do to change the character (A, B, C, D) in the variable c to the column index in the array? Check the program example on page 347. I have included the LetterCount program in the Chapter Seven Activities.
The program checks the array to see if the seat is available. An X in the array indicates the seat is not available.
If the seat is available, assign an X to that position in the array. If its unavailable, display a message to the passenger. Use the displaySeats method after each row/seat entry.
After some seats are assigned, the layout may look like this:
1 X B C X
2 A B C D
3 A X C X
4 A B C D
5 A B C D
Continue processing requests until the user enters -1 for seat.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
