I am simulating an airport which 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 has the higher priority. The user enters commands takeoffflightSymbol, landflightSymbol, 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 flightsymbol. But I can't seem to find the problem for the following code. Help!
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 close 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"))
{
System.exit(0);
}
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();
}
}
When the simulation is running, other than the quit function, all the other functions produce java.lang.NullPointerException errors.