Your application should display the following alternatives: Please type 1 for First Class and Please type 2 for Economy. If the user types 1, the application should assign a seat in the first-class section (seat 1-5). If the user types 2, your application should assign a seat in the economy section (seats 6-10). Your application should then display a boarding pass indicating the person’s seat number and whether it is in the first-class or economy section of the plane.
Use one-dimensional arrays of primitive type Boolean to represent the seating chart of the plane. Initialise all the elements in the array to false and to indicate that all the seats are empty. As each seat is assigned, set the corresponding elements of the array to true to indicate that the seat is no longer available.
When the economy section is full, your application should ask the person if it is acceptable to be placed in the first-class section (and vice versa). If yes, make the appropriate seat assignment. If no, display the message “Next flight leaves in three hours”.
import java.util.Scanner;
public class a {
public static void main(String[] args) {
Scanner input=new Scanner(System.in);
//Boolean[]r=new Boolean[10];
int f=0;
int e=5;
int exit;
do{
System.out.println();
System.out.println("~~~~~~~~~~~~~~~~~AIRLINE RESERVATION SYSTEM~~~~~~~~~~~~~~~~~~~");
System.out.println();
System.out.println("\t\tPLEASE CHOOSE:");
System.out.println("\t\t1. FIRST CLASS");
System.out.println("\t\t2. ECONOMY");
int section=input.nextInt();
switch(section){
case 1:
System.out.println();
System.out.println("YOUR SEATS IS IN THE FIRST CLASS SECTION.");
f++;
if (f<=5){
System.out.println("Your seat number is "+f);
System.out.println();
}
else{
System.out.println();
System.out.println("The first class section is full.");
System.out.println("Do you want to be placed at the economy section?(1.yes\t2.no)");
int full=input.nextInt();
if (full==1){
System.out.println("Press 1 to go to the main menu.");
}
else{
System.out.println("next flight leaves in 3 hours.");
}
}
break;
case 2:
System.out.println();
System.out.println("YOUR SEATS IS IN THE ECONOMY SECTION.");
e++;
if ((e>5)&&(e<=10)){
System.out.println("Your seat number is "+e);
System.out.println();
}
else{
System.out.println();
System.out.println("The economy class section is full.");
System.out.println("Do you want to be placed at the first class section?(1.yes\t2.no)");
int full=input.nextInt();
if (full==1){
System.out.println("Press 1 to go to the main menu.");
}
else{
System.out.println("next flight leaves in 3 hours.");
}
}
}
System.out.println();
System.out.println("1.main menu\t2.exit");
exit=input.nextInt();
}while (exit==1);
System.out.println();
System.out.println("~~~~~~~~~~~~~Enjoy your journey!!~~~~~~~~~~~~~~~");
}
}

New Topic/Question
Reply




MultiQuote




|