the program must prompt the user to enter the following information:
Ticket type(1st class or economy class)
For economy class, the non-smoking or smoking
Desired Seat
Output the seating plan in the ff: format
| A | B | C | D | E | F |
Row1 | * | * | * | * | * | * |
Row2 | * | * | X | * | * | * |
Row3 | * | * | * | * | * | * |
Row4 | * | * | * | * | * | * |
Row5 | * | * | * | * | X | * |
Row6 | * | * | * | * | * | * |
Row7 | * | * | * | X | * | * |
Row8 | * | * | X | * | * | * |
Row9 | * | X | * | * | * | * |
Row10 | * | * | * | * | * | * |
Row11 | * | * | * | * | * | X |
Row12 | * | * | * | * | * | * |
Row13 | * | * | * | * | * | * |
NOTE:
* - indicates the seat is available
X - the seat has been assigned
Make this a menu driven program. Show the user's choice and allow the user to make appropriate choices
Here is my approach guyz
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 Java 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';
}
else{
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++;
}
}
}
}
whenever i input another ticket it does not incorporate the result of my first input
plus i need to know how to tell if i have chosen a reserved seat(X)

New Topic/Question
Reply
MultiQuote








|