Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a Java class called SeatAssignment to assign passengers seats in an airpla

ID: 3639863 • Letter: W

Question

Write a Java class called SeatAssignment to assign passengers seats in an airplane. In this program, you should assume that there’s a small airplane with seat numberings as follows:

1 AB CD
2 AB CD
3 AB CD
4 AB CD
5 AB CD
6 AB CD
7 AB CD

Your program should display the seat pattern, with an ‘X’ marking the seats already assigned. For example, after seats 1A, 2B, and 4C are taken, the display should look like:

1 XB CD
2 AX CD
3 AB CD
4 AB XD
5 AB CD
6 AB CD
7 AB CD

After displaying the seats available, the program should prompt for the seat desired. Then, a user
can type in a seat. Then the available seats should be updated. Your program should continue until
all seats are filled or until the user signals that the program should end. If the user types in a seat
that is already taken, the program should say that the seat is occupied and ask for another choice. If
the user types in an invalid seat number, the program should say that the seat is invalid and ask for
another choice.

Explanation / Answer

please rate - thanks

import java.util.*;
public class airplane2
{public static void main(String[] args) {
char[][] seats = new char[7][4];
int i,filled=0,row,col;
char c;
String input;
for (i=0;i<7;i++)
   for(c='A';c<='D';c++)
       seats[i][(int)(c-'A')]=c;
Scanner in = new Scanner(System.in);
printSeats(seats);
System.out.print("Enter seat selection(e.g.'1A')blank line to quit: ");
input=in.nextLine();
while((filled<28)&&(input.length()>0))
{row=(int)(input.charAt(0)-'1');
col=(int)(Character.toUpperCase(input.charAt(1))-'A');
if(row<0||row>6||col<0||col>3)
    System.out.println("Invalid seat selection");
else if(seats[row][col]=='X')
     System.out.println("Sorry-that seat is taken");
else
    {filled++;
    seats[row][col]='X';
    }
printSeats(seats);   
System.out.print("Enter seat selection(e.g.'1A')blank line to quit: ");
input=in.nextLine();
}
if(filled==28)
    System.out.println("Plane full");
System.out.println("Final seat assignments: ");
printSeats(seats);

}
private static void printSeats(char[][] seats)
{int i,j;
for (i=0;i<7;i++)
{System.out.print((i+1)+" ");
for(j=0;j<4;j++)
    System.out.print(seats[i][j]+" ");
System.out.println();
}
}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote