2. Write a Java program that can be used to assign seats for McC Loose-Wing Airl
ID: 3587129 • Letter: 2
Question
2. Write a Java program that can be used to assign seats for McC Loose-Wing Airline. The airline has 13 rows, with 6 seats in each row. Rows 1 and 2 are first class; the remaining rows are economy class. Rows 1 through 7 are nonsmoking. Your program must prompt the user to enter the following information: Use the IntClass (for row number) and CharClass (for column number)found on the subsequent pages Ticket type (first class or economy class) For economy class, the smoking or nonsmoking section Desired seat Output the seating plan in the following form: A B C D EF Row 1 X Row 2 Row 3 Row 4 Row 5 X Row 6 Row 7 Row 8 X Row 9 Row 10 Row 11 Row 12 Row 13 X Here, indicates that the seat is available; X indicates that the seat has been assigned. Make this a menu-driven program; show the user's choices and allow the user to make the appropriate choices. Output the seating chart after each choice is made. economy, smoking, 88: first-class, 1c, economy, nonsmoking,.5F: first-class, 2D: économy, smoking, 13AExplanation / Answer
The code is given below:
import java.util.*;
public class Multidim{
public static void main(String[]args){
Scanner sc = new Scanner(System.in);
char array[][] = new char[14][7];
int row=1;
int k=1;;
int r=0,c=0;
int O=0;
System.out.println("Welcome to Loose Wing Airlines!");
row=1;
System.out.println(" | A | B | C | D | E | F |" );
for(int i=0;i<13;i++){
for(int j=0;j<6;j++){
array[i][j]='*';
if(j==0){
if(row<=9)
System.out.print("Row"+row+" ");
else
System.out.print("Row"+row+" ");
}
System.out.print(" | "+array[i][j]);
}
System.out.print(" |");
System.out.println();
row++;
}
for(O=0;O<13;O++){ //just playing it out to enter another ticket
array[r][c]='X';
System.out.print("Please Select your ticket type[1]First Class[2]Economy Class");
int m = sc.nextInt();
switch(m){
case 1: System.out.println("Please Enter Desired Seat");
System.out.print("Enter Row[1-2]:");
r = sc.nextInt();
System.out.print("Enter Column[1=A|2=B|3=C|4=D|5=E|6=F]:");
c = sc.nextInt();
break;
case 2:System.out.print("Smoking(1) or Non-smoking(2)");
int sn = sc.nextInt();
if(sn==1){
System.out.print("Enter Row[3-7]:");
r = sc.nextInt();
System.out.print("Enter Column[1=A|2=B|3=C|4=D|5=E|6=F]:");
c=sc.nextInt();
}
else if(sn==2){
System.out.print("Enter Row[8-13]:");
r = sc.nextInt();
System.out.print("Enter Column[1=A|2=B|3=C|4=D|5=E|6=F]:");
c=sc.nextInt();
}
break;
default: System.out.print("Invalid!");
break;
}
System.out.println(" | A | B | C | D | E | F |" );
row=1;
r=r-1;
c=c-1;
for(int i=0;i<13;i++){
for(int j=0;j<6;j++){
if(r==i && c==j ){
array[i][j]='X';
}
if(j==0){
if(row<=9)
System.out.print("Row"+row+" ");
else
System.out.print("Row"+row+" ");
}
System.out.print(" | "+array[i][j]);
}
System.out.print(" |");
System.out.println();
row++;
}
}
}
}
---------------------------------------------------------------------
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.