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

Create a AirportSimulator class that extends the provided Airport abstract class

ID: 3720803 • Letter: C

Question

Create a AirportSimulator class that extends the provided Airport abstract class

Feature

Signature

Requirement

Constructor

AirportSimulator (int numRunways)

Precondition: numRunways >= 1;
Postcondition: airport simulator with specified number of runways and default arrival and departure runway reserve times;

AirportSimulator(int numRunways,

int arrivalReserveTime,

int departureReserveTime)

Precondition: numRunways >= 1, arrivalReserveTime >= 1, departureReserveTime >= 1;

Postcondition: airport simulator with specified number of runways and arrival and departure runway reserve times (in minutes);

Methods

public void processEventFile(String filename)

Precondition: filename contains path to the events file; events file is pipe-delimited file containing the scheduled time, event type (ARRIVAL or DEPARTURE) and a Flight ID.

public Event[] getFlightsHandled();

Returns an array of all flights processed

Feature

Signature

Requirement

Constructor

AirportSimulator (int numRunways)

Precondition: numRunways >= 1;
Postcondition: airport simulator with specified number of runways and default arrival and departure runway reserve times;

AirportSimulator(int numRunways,

int arrivalReserveTime,

int departureReserveTime)

Precondition: numRunways >= 1, arrivalReserveTime >= 1, departureReserveTime >= 1;

Postcondition: airport simulator with specified number of runways and arrival and departure runway reserve times (in minutes);

Methods

public void processEventFile(String filename)

Precondition: filename contains path to the events file; events file is pipe-delimited file containing the scheduled time, event type (ARRIVAL or DEPARTURE) and a Flight ID.

public Event[] getFlightsHandled();

Returns an array of all flights processed

Explanation / Answer

AirportSimulation.java:

import java.awt.Event;

import java.util.*;

import java.util.concurrent.LinkedBlockingQueue;

// create the class

public class AirportSimulation extends Airport

{

static boolean flag1;

static boolean flag2;

// default constructor.

public AirportSimulation()

{

super();

}

// parameterised constructor.

public AirportSimulation(int numRunways)

{

if(Math.random() < (1.0 / numRunways))

flag1 = true;

else

flag1 = false;

}

// parameterised constructor.

public AirportSimulation(int numRunways,

int arrivalReserveTime,

int departureReserveTime)

{

if(departureReserveTime - arrivalReserveTime>

numRunways)

{

flag2 = true;

}

else

{

flag2 = false;

}

}

// Start the main method.

public static void main(String[] args)

{

Scanner in = new Scanner(System.in);

System.out.print("Enter time needed "+

"for plane to land: ");

int landTime = in.nextInt();

System.out.print("enter the time "+

"needed t take off: ");

int takeoffTime = in.nextInt();

System.out.print("Enter time between"+

" landing and queuing: ");

int avgArrivalInterval = in.nextInt();

System.out.print("enter time between "+

"arrieval and take off: ");

int avgDepartureInterval = in.nextInt();

System.out.print("Time taken in the "+

"queue standing: ");

int crashLimit = in.nextInt();

System.out.print("total time taken: ");

int totalTime = in.nextInt();

// craete an object of the class.

AirportSimulation as =

new AirportSimulation();

int TimeInTakeoff = 0;

int numLand = 0, numTakeoff = 0;

int numPlanesCrashed = 0;

// craete an object of the queue class.

Queue<Integer> lQ =

new LinkedBlockingQueue<Integer>();

// craete an object of the queue class.

Queue<Integer> tQ =

new LinkedBlockingQueue<Integer>();

for(int i = 0; i < totalTime; ++i)

{

// call the constructor.

as = new AirportSimulation

(avgArrivalInterval);

if(flag1)

{

lQ.add(i);

}

// pass the value to the constrctor.

as = new AirportSimulation

(avgDepartureInterval);

if(flag1)

{

tQ.add(i);

}

while(true)

{

while(!lQ.isEmpty())

{

as = new AirportSimulation

(crashLimit,

lQ.peek(), i);

if(flag2)

{

lQ.remove();

numPlanesCrashed++;

}

else

{

break;

}

}

if(!lQ.isEmpty())

{

lQ.remove();

numLand++;

int j;

for(j = i; j < landTime + i && j<

totalTime; ++j)

{

as = new AirportSimulation

(avgArrivalInterval);

if(flag1)

{

lQ.add(j);

}

as = new AirportSimulation

(avgDepartureInterval);

if(flag1)

{

tQ.add(j);

}

}

i = j;

if(i >= totalTime)

{

break;

}

}

else

{

break;

}

}

if(!tQ.isEmpty())

{

int nextPlane = tQ.peek();

tQ.remove();

numTakeoff++;

TimeInTakeoff += (i - nextPlane);

int j;

for(j = i; j < takeoffTime + i && j<

totalTime; ++j)

{

as = new AirportSimulation

(avgArrivalInterval);

if(flag1)

{

lQ.add(j);

}

as = new AirportSimulation

(avgDepartureInterval);

if(flag1)

{

tQ.add(j);

}

}

i = j;

}

}

while(!lQ.isEmpty())

{

as = new AirportSimulation( crashLimit,

lQ.peek(), totalTime);

if(flag2)

{

lQ.remove();

numPlanesCrashed++;

}

else

{

break;

}

}

System.out.println

("Number of plane that take off: " +

numTakeoff);

System.out.println

("The number of plane is landed: " +

numLand);

System.out.println

("Number of plane that crashed: " +

numPlanesCrashed);

System.out.println

("Plane taken time for takeoff in the queue: " +

TimeInTakeoff / (double)numTakeoff);

System.out.println

("Time taken to land on the queue: " +

TimeInTakeoff / (double)numLand);

}

@Override

public void processEventFile(String filename)

{

// TODO Auto-generated method stub

}

@Override

public Event[] getFlightsHandled()

{

// TODO Auto-generated method stub

return null;

}

}

Airport.java:

import java.awt.Event;

public abstract class Airport

{

public abstract void processEventFile(String filename);

public abstract Event[] getFlightsHandled();

}