Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

An airport has only one runway. When it is busy, planes wishing to take off or l

ID: 663118 • Letter: A

Question

An airport has only one runway. When it is busy, planes wishing to take off or land have to wait. Implement a simulation, using two queues, one each for the planes waiting to take off and land. Landing planes get priority. The user enters commands takeoff flightSymbol, land flightSymbol, next, and quit. The first two commands place the flight in the appropriate queue. The next command finishes the current takeoff or landing and enables the next one, printing the action (takeoff or land) and the flight symbol.

This is java. I need help with my program. It is giving me errors

import java.util.Queue;
import java.util.Scanner;

public class Runway
{
   public Scanner in;
   public Queue<String> takingOff;
   public Queue<String> landing;

   public Runway()
   {
in = new Scanner(System.in);
boolean done = false;
while (!done)
{
   System.out.println("Type TAKEOFF/LAND followed by Fight Number to Queue a plane");
   System.out.println("Type NEXT to perform the next action, or QUIT to quit the simulation");
   String action = in.next();
   if (action.equals("TAKEOFF"))
   {
String flight = in.next();
takingOff.add(flight);
   }
   else if (action.equals("LAND"))
   {
String flight = in.next();
landing.add(flight );
   }
else if (action.equals("NEXT"))
   {
handleNextAction();
   }
   else if (action.equals("QUIT"))
   {
done = true;
   }
   else {
System.out.println("ERROR - not a valid command");
   }
}
   }

   public void handleNextAction()
   {
if (landing.size() > 0)
{
   String flight = landing.remove();
   System.out.println("Flight " + flight + " is landing. ");
}
else if (takingOff.size() > 0)
{
   String flight = takingOff.remove();
   System.out.println("Flight " + flight + " is taking off.");
}
else
{
   System.out.println("There are no flights waiting to take off or land");
}
   }

   public static void main (String[] args)
   {
Runway simulator = new Runway();
   }
}

Explanation / Answer

package NIIT;

import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

public class Runway
{
public Scanner in;
public Queue<String> takingOff;
public Queue<String> landing;

public Runway()
{
   takingOff=new LinkedList<String>();
   landing=new LinkedList<String>();
in = new Scanner(System.in);
boolean done = false;
  
while (!done)
{
  
System.out.println("Type TAKEOFF/LAND followed by Fight Number to Queue a plane");
System.out.println("Type NEXT to perform the next action, or QUIT to quit the simulation");
String action = in.next();
if (action.equals("TAKEOFF"))
{
   System.out.println("Enter flight Number:");
String flight = in.next();
takingOff.add(flight);
}
else if (action.equals("LAND"))
{
   System.out.println("Enter flight Number:");
String flight = in.next();
landing.add(flight);
}
else if (action.equals("NEXT"))
{
handleNextAction();
}
else if (action.equals("QUIT"))
{
done = true;
}
else {
System.out.println("ERROR - not a valid command");
}
}
}

public void handleNextAction()
{
if (landing.size() > 0)
{
String flight = landing.remove();
System.out.println("Flight " + flight + " is landing. ");
}
else if (takingOff.size() > 0)
{
String flight = takingOff.remove();
System.out.println("Flight " + flight + " is taking off.");
}
else
{
System.out.println("There are no flights waiting to take off or land");
}
}

public static void main (String[] args)
{
Runway simulator = new Runway();
}
}

IN your code you need to understand that you should instantiate your object takingoff and landing;

as Queue is an Interface you cannot create directly,so you should create an instance of class implementing Queue interface so i created instance of linkedlist class.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote