Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Fix the errors in my java program. and it should not effect the code functionality import java.util.Scanner; public class FlightManagementSystem { public static void main
Fix the errors in my java program. and it should not effect the code functionality
import java.util.Scanner; public class FlightManagementSystem { public static void main(String [] args) { int fuel =0; String st; Arrival arrival=new Arrival();//Arrival class object Departure departure= new Departure();//departure class object int passanger=0; Scanner input=new Scanner(System.in); int opt=1; System.out.printf(" \t\t welcome to Heathrow international Airport "); while(opt!=0) { System.out.printf(" \t\t 1: insert information of arrival flight"); System.out.printf(" \t\t 2: insert information of departure flight"); System.out.printf(" \t\t 3: press 3 to land the flight"); System.out.printf(" \t\t 4: press 4 to take off the flight"); System.out.printf(" \t\t 5: press 5 for emergency flight "); System.out.printf(" \t\t enter your choice: "); opt=input.nextInt(); switch(opt) { case 1: System.out.printf(" \t\t enter flight id "); st=input.next(); System.out.printf(" \t\t enter fuel "); fuel=input.nextInt(); if(fuel<=0) { System.out.printf(" fuel can not be 0 try again"); break; } System.out.printf(" \t\t enter passanger "); passanger=input.nextInt(); if(passanger<=0) { System.out.printf(" passanger can not be 0 try again"); break; }//passing variable to the time class constructor Flight flight=new Flight(st,fuel,passanger);//passing variable to the flight class object if(!arrival.isFull()) arrival.Enqueue(flight); else System.out.println("flight can not be enetered because runway is full"); break; case 2: System.out.printf(" \t\t enter flight id "); st=input.next(); System.out.printf(" \t\t enter fuel "); fuel=input.nextInt(); if(fuel<=0) { System.out.printf(" fuel can not be 0 try again"); break; } System.out.printf(" \t\t enter passanger "); passanger=input.nextInt(); if(passanger<=0) { System.out.printf(" passanger can not be 0 try again"); break; } Flight flight1=new Flight(st,fuel,passanger); if(!departure.isFull()) departure.Enqueue(flight1); else System.out.println("flight can not be enetered because runway is full"); break; case 3: arrival.Dequeue(); break; case 4: departure.Dequeue(); break; case 5: System.out.printf(" \t\t eneter flight id:"); st=input.next(); if(arrival.Emergency(st)){ System.out.println("flight landed successfully"); } else System.out.println("flight landed unsuccessfully"); break; case 6: System.out.printf(" arrival flights: "); arrival.Display(); System.out.printf("departure flights: "); departure.Display(); break; } } } class Arrival{ private final int SIZE= 10; private Flight [] LQ=new Flight[SIZE]; private Flight [] LQ1=new Flight[SIZE]; private Flight [] tempArray=new Flight[SIZE]; int tempCounter; private int temp; private int a; private int LQcounter; private int LQcounter1; public Arrival() { LQcounter=0; LQcounter1=0; temp=0; a=0; tempCounter=0; } public boolean Enqueue(Flight f) {//load balanced and self organized flights if(LQcounter==LQcounter1) { LQ[LQcounter++]=f; return true; } if(LQcounter>LQcounter1) { LQ1[LQcounter1++]=f; return true; } if(LQcounterreturn true; } return false; } public boolean Dequeue() { Flight tempfl; Flight tempf2; int front=0; tempfl=LQ[front]; tempf2=LQ1[front]; for(int i=0;i 1]; } for(int i=0;i 1]; } LQcounter--; LQcounter1--; return true; } public boolean isFull() { if(LQcounter>=SIZE&&LQcounter1>=SIZE) { return true; } return false; } public boolean isEmpty() { if(LQcounter<=0&&LQcounter1<=0) { return true; } return false; } public boolean Emergency(String id) { int top=0; int a=0; String St=id; Flight stack[]=new Flight[SIZE]; Flight tempflight; if(LQcheck(St)) { a=LQcounter-1; while(!LQ[a].getFlightid().equals(id)) { stack[top++]=LQ[a--]; } tempArray[tempCounter++]=LQ[a]; while(top>=0) { LQ[a++]=stack[top--]; } LQcounter--; return true; } if(LQcheck1(id)) { int b=LQcounter1-1; while(!LQ1[b].getFlightid().equals(id)) { stack[top++]=LQ1[b--]; } tempArray[tempCounter++]=LQ1[b]; while(top>=0) { LQ1[b++]=stack[top--]; } LQcounter1--; return true; } return false; } public boolean LQcheck(String id) { for(int i=0; i<=LQcounter-1;i++) { if(LQ[i].getFlightid().equals(id)) { return true; } } return false; } public boolean LQcheck1(String id) { for(int i=0; i<=LQcounter1-1;i++) { if(LQ1[i].getFlightid().equals(id)) { return true; } } return false; } public void Display() { for(int i=0;i out.printf(" flight id:%s", LQ[i].getFlightid()); } for(int i=0;i out.printf(" flight id:%s", LQ1[i].getFlightid()); } } } class Departure{ private final int SIZE= 10; private Flight [] TO1=new Flight[SIZE]; private Flight [] TO2=new Flight[SIZE]; public int temp; private int a; private int TOcounter1; private int TOcounter2; public Departure() { TOcounter1=0; TOcounter2=0; temp=0; a=0; } public boolean Enqueue(Flight f) { if(TOcounter1==TOcounter2) { TO1[TOcounter1++]=f; return true; } if(TOcounter1>TOcounter2) { TO2[TOcounter2++]=f; return true; } if(TOcounter1 return true; } return false; } public boolean isFull() { if(TOcounter1>=SIZE&&TOcounter2>=SIZE) { return true; } return false; } public boolean isEmpty() { if(TOcounter1<=0&&TOcounter2<=0) { return true; } return false; } public boolean Dequeue() { Flight tempfl; Flight tempf2; int front=0; tempfl=TO1[front]; tempf2=TO2[front]; for(int i=0;i 1]; } for(int i=0;i 1]; } TOcounter1--; TOcounter2--; return true; } public void displayReport() { float holdAverage=0; holdAverage=temp/a; System.out.printf("average take off timing is: %f ", holdAverage); } public void Display() { for(int i=0;i out.printf(" flight id:%s", TO1[i].getFlightid()); } for(int i=0;i out.printf(" flight id:%s", TO2[i].getFlightid()); } } } class Flight { public String flightid; public int fuel; public int Passanger; public Flight(String flightid,int fuel,int Passanger) { this.flightid=flightid; this.fuel=fuel; this.Passanger=Passanger; } public void setFlightID(String flightid) { this.flightid=flightid; } public void setFuel(int fuel) { this.fuel=fuel; } public void setPassanger(int Passanger) { this.Passanger=Passanger; } public String getFlightid() { return flightid; } public int getFuel() { return fuel; } public int getPassanger() { return Passanger; } } }
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