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

Write a simulation program for a small airport that has only one runway. · There

ID: 3594782 • Letter: W

Question

Write a simulation program for a small airport that has only one runway.

·

There will be a queue of planes waiting to land and a queue of planes waiting to take off.

However, only one plane can use the runway at a time, so there can be only one takeoff

or one landing in progress at any one time.

·

Assume that all takeoffs take the same amount of time.

·

Assume that all landings take the same amount of time, but this need not be the same as

the takeoff time.

·

Assume that planes arrive for landing at random times but with a specified probability of

a plane arriving during any given minute.

·

Similarly, assume that planes arrive at the takeoff queue at random times but with a

(possibly different) specified probability of a departure. (Despite the fact that takeoffs

and landings are scheduled, delays make this a reasonable assumption.)

·

Since it is more expensive and more dangerous to keep a plane waiting to land than it is

to keep a plane waiting to take off, landings will have priority over takeoffs.

·

Thus, as long as some plane is waiting to land, no plane can take off.

·

Use a clock that is an integer variable that counts the number of minutes simulated.

·

Use a random number generator to simulate arrival and departure times of airplanes.

This simulation can be used, among other things, for deciding when the air traffic has become so

heavy that a second runway must be built. Hence, the simulation will simulate disaster conditions

in which planes crash because they run out of fuel while waiting too long in the landing queue.

By examining the simulated situation, the airport authority hopes to avoid real tragedy.

·

Assume all planes can remain in the queue for the same amount of time before they run

out of fuel.

·

If a plane runs out of fuel, your simulation will not discover this until the simulated plane

is removed from the queue; at that point, the fact that the plane crashed is recorded, that

plane is discarded, and the next plane is processed.

·

A crashed plane is not considered in the calculation of waiting time.

·

At the end of the simulated time, the landing queue is examined to see whether any of the

planes in the simulated queue have crashed.

·

You can disregard the planes left in the queue at the end of the simulation, other than

those that crashed for lack of sufficient fuel.

Use the following input and output specifications:

Note: Ask the user to enter the input values. Your program will printout the ouput values.

Input:

(1) The amount of time needed for one plane to land;

(2) the amount of time needed for one plane to take off;

(3) the probability of an arrival of a plane into the landing queue;

(4) the probability of an arrival of a plane into the takeoff queue;

(5) the maximum amount of time that a plane can stay in the landing queue without

running out of fuel and crashing; and

(6) the total length of time to be simulated.

Output:

(1) The number of planes that took off in the simulated time;

   (2) the number of planes that landed in the simulated time;

   (3) the number of planes that crashed because they ran out of fuel before they could

land;

   (4) the average time that a plane spent in the takeoff queue; and

   (5) the average time that a plane spent in the landing queue.

Assignment 7 is to create a detailed design of this system. This is to be a text document that will

contain the following:

1.    A list of all of the classes needed for this simulation.

·

Each class will have a description of what the class is for and what it does.

·

The method headers for all of the methods in each class.

·

A description of what the method is for and what it does: this will include the

Preconditions and Postcondition. The method description should include a brief

description of how the method is going to accomplish its functionality. This should not

be code, but rather a textural description, although some sudo code is acceptable. The

method parameters and return values should be included, with a description of what they

are.

·

A list of the class fields and what they are used for.

2.

UML class diagrams for each class.

3.

This detail design should be complete enough so that I can determine if your design is going

to fulfil the requirements of the assignment.

Assignemt 8 is to create the code from your detail design and to test it to verify that it works

correctly. It is acceptable to deviate, as needed, from your detail design during the coding phase

if need be, to make this work correctly.

The file with the main method is to be named Airport.jav

Explanation / Answer

import java.io.*;

public class RunwaySimulation

{

private final int TAKEOFF_TIME = 2;

private final int LANDING_TIME = 3;

private final int MAX_FLIGHT_TIME = 9;

private final int TOTAL_RUN_TIME = 30;

private final int TAKEOFF_AVERAGE = 7;

private final int LANDING_AVERAGE = 5;

private double landingProb;

private double takeoffProb;

private int totalPlanesTakeoff;

private int totalPlanesLanding;

private int planesCrashed;

private int averageTakeoffQueue;

private int averageLandingQueue;

private int currentTime;

private int planeNumber;

private LinkedQueue<Plane> queueLanding = new LinkedQueue<Plane>();

private LinkedQueue<Plane> queueTakeoff = new LinkedQueue<Plane>();

private LinkedQueue<String> queueStats = new LinkedQueue<String>();

private LinkedStack<Plane> stack = new LinkedStack<Plane>();

private LinkedStack<Integer> stackTime = new LinkedStack<Integer>();

public RunwaySimulation()

{

landingProb = (double)LANDING_AVERAGE/TOTAL_RUN_TIME;

takeoffProb = (double)TAKEOFF_AVERAGE/TOTAL_RUN_TIME;

totalPlanesTakeoff = 0;

totalPlanesLanding = 0;

planesCrashed = 0;

averageTakeoffQueue = 0;

averageLandingQueue = 0;

currentTime = 0;

planeNumber = 0;

try

{

FileWriter fileOut = new FileWriter("Output.txt", true);

PrintWriter pw = new PrintWriter(fileOut);

simulate(pw);

}

catch(IOException e)

{

System.out.println("Output.txt could not be found.");

System.exit(0);

}

}

public void simulate(PrintWriter pw)

{

BooleanSource takeoff = new BooleanSource(takeoffProb);

BooleanSource landing = new BooleanSource(landingProb);

Runway runway = new Runway(TAKEOFF_TIME, LANDING_TIME);

Averager avgTakeoff = new Averager();

Averager avgLanding = new Averager();

if(takeoffProb < 0 || takeoffProb > 1 || landingProb < 0 ||

landingProb > 1 || TOTAL_RUN_TIME < 0)

{

throw new IllegalArgumentException("The values are not in range.");

}

for(currentTime = 0; currentTime <= TOTAL_RUN_TIME; currentTime++)

{

String planeTakeoff = null;

String planeLanding = null;

if(takeoff.query())

{

totalPlanesTakeoff++;

Plane planeT = new Plane(currentTime, 'T');

queueTakeoff.add(planeT);

planeTakeoff = "Plane #" + planeT.getPlaneNo();

}

if(landing.query())

{

totalPlanesLanding++;

Plane planeL = new Plane(currentTime, 'L');

queueLanding.add(planeL);

planeLanding = "Plane #" + planeL.getPlaneNo();

}

if(!runway.isBusy() && (!queueTakeoff.isEmpty() || !queueLanding.isEmpty()))

{

planeNumber = runwayBusy(runway, avgTakeoff, avgLanding, currentTime);

}

printTimeUnit(currentTime, runway, planeNumber, planeTakeoff,

planeLanding);

runway.reduceRemainingTime();

}

printSimulationSummary(pw, avgTakeoff, avgLanding);

pw.print(" ");

pw.print("Description of use of the runway: ");

pw.print(" ");

printAllStats(pw);

printCrashedPlanes(pw);

pw.close();

}

private int runwayBusy(Runway runway, Averager avgTakeoff, Averager avgLanding,

int currentTime)

{

Plane plane;

int answer = -1;

if(queueLanding.isEmpty())

{

plane = (Plane)queueTakeoff.remove();

runway.startUsingRunway(plane.getOperation());

avgTakeoff.addNumber(currentTime - plane.getTime());

System.out.println(currentTime - plane.getTime());

answer = plane.getPlaneNo();

}

else

{

plane = (Plane)queueLanding.remove();

if((currentTime - plane.getTime()) <= MAX_FLIGHT_TIME)

{

runway.startUsingRunway(plane.getOperation());

answer = plane.getPlaneNo();

avgLanding.addNumber(currentTime - plane.getTime());

}

else

{

planesCrashed++;

stack.push(plane);

stackTime.push(currentTime);

if(!queueLanding.isEmpty())

{

plane = (Plane)queueLanding.remove();

runway.startUsingRunway(plane.getOperation());

answer = plane.getPlaneNo();

avgLanding.addNumber(currentTime - plane.getTime());

}

}

}

return answer;

}

private void printCrashedPlanes(PrintWriter pw)

{

if(!stack.isEmpty())

{

pw.print("Crashed Planes: ");

for(int i = stack.size(); i > 0; i--)

{

Plane plane = (Plane)stack.pop();

pw.print("Plane #" + plane.getPlaneNo() + " crashed at minute " +

stackTime.pop() + " ");

}

}

else

{

pw.print("No planes have crashed during this simulation.");

}

}

public void printTimeUnit(int time, Runway runway, int planeNumber,

String planeTakeoff, String planeLanding)

{

String string;

string = " min " + time + ": ";

string = string + " Arrived for takeoff: ";

if(planeTakeoff == null)

{

string = string + " ";

}

else

{

string = string + planeTakeoff + " ";

}

string = string + " Arrived for Landing: ";

if(planeLanding == null)

{

string = string + " ";

}

else

{

string = string + planeLanding + " ";     

}

string = string + " Runway: ";

if(runway.kindOfOperation() == 'T')

{

string = string + "Plane #" + planeNumber + " Takeoff ";

}

else if(runway.kindOfOperation() == 'I')

{

string = string + "Idle ";

}

else if(runway.kindOfOperation() == 'L')

{

string = string + "Plane #" + planeNumber + " Landing ";

}

string = string + " ";

queueStats.add(string);

}

public void printAllStats(PrintWriter pw)

{

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

{

pw.print(queueStats.remove());

}

}

public void printSimulationSummary(PrintWriter pw, Averager avgTakeoff,

Averager avgLanding)

{

averageTakeoffQueue = (int)avgTakeoff.average();

averageLandingQueue = (int)avgLanding.average();

pw.print("The time of simulation is: " + TOTAL_RUN_TIME

                   + " minutes ");

pw.print("The amount of time that is needed for one plane to take off is: "

                   + TAKEOFF_TIME + " minutes ");

pw.print("The amount of time that is needed for one plane to land is: "

                   + LANDING_TIME + " minutes ");

pw.print("The average amount of time between arrival of planes to the takeoff"

                   + " queue is: " + TAKEOFF_AVERAGE + " minutes ");

pw.print("The average amount of time between arrival of planes to the landing"

                   + " queue is: " + LANDING_AVERAGE + " minutes ");

pw.print("The maximum time a plane can stay in the landing queue before crashing"

                   + " is: " + MAX_FLIGHT_TIME + " minutes ");

pw.print(" ");

pw.print("No. of planes that came to the runway for takeoff: " +

                   totalPlanesTakeoff + " ");

pw.print("No. of planes that came to the runway for landing: " +

                   totalPlanesLanding + " ");

pw.print("No. of planes that crashed: "

                   + planesCrashed + " ");

pw.print("The average time a plane spent on the takeoff queue is: "

                   + averageTakeoffQueue + " min ");

pw.print("The average time a plane spent on the landing queue is: "

                   + averageLandingQueue + " min ");

}

public static void main(String[] args)

{

RunwaySimulation sim = new RunwaySimulation();

System.exit(0);

}

}

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