Question
QUESTION : Please tell mE what is done in this program in detail.. import java.util.*; class AirLineReservation { boolean seatchart[]; //An array of seatchart int
QUESTION : Please tell mE what is done in this program in detail..
import java.util.*; class AirLineReservation { boolean seatchart[]; //An array of seatchart int economy,firstclass; //Count of economy and firstclass AirLineReservation() //Default constructor to initialize false to all { seatchart=new boolean[10]; for(int i=0;i<10;i++) seatchart[i]=false; economy=5; firstclass=0; } void bookEconomy() //method to book economy as true { if(economy<10) seatchart[economy++]=true; } void bookFirstClass() //method to book firstclass as true
{ if(firstclass<5) seatchart[firstclass++]=true; } void showStatus() //Displaying status { System.out.println("First-Class status chart "); System.out.println("Seat no.\t Available(true/false) "); for(int i=0;i<5;i++) System.out.println(i+1+"\t"+seatchart[i]); //printing each of the fields System.out.println("Economy section status chart "); System.out.println("Seat no.\t Available(true/false) "); for(int i=5;i<10;i++) System.out.println(i+1+"\t"+seatchart[i]); } public static void main(String args[]) { AirLineReservation ar=new AirLineReservation(); Scanner s=new Scanner(System.in); int choice=0; char b; while(choice!=3) //Repeat until false { System.out.println("Enter your reservation choice(1-for Economy,2-for First class an 3-for exit"); choice=s.nextInt(); //taking choice if(choice==2) //if choice is firstclass option 2 { if(ar.firstclass==5) //if first class is full { System.out.println("First class is full, do you want Economy?"); b=s.next().charAt(0); //take choice for economy if(b=='y') //if yes book economy ar.bookEconomy(); } else ar.bookFirstClass(); //otherwise bookfirstclass } else if(choice==1) //if choice is economy { if(ar.economy==10) //if economy is full { System.out.println("Economy class is full, do you want First class?"); b=s.next().charAt(0); //input choice for first class if(b=='y') ar.bookFirstClass(); //then book first class } else ar.bookEconomy(); //otherwise economy } else if(choice==3) //choice 3 for exit System.exit(0); else System.out.println(" Invalid choice "); //Invalid choice error ar.showStatus(); //display current availability } } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started