For this assignment, you will be programming an airport simulator. The airport has one runway, and a plane can either be taking off or landing on it at any given unit of time. There will be a queue of...

1 answer below »

For this assignment, you will be programming an airport simulator. The airport has one runway, and a plane can either be taking off or landing on it at any given unit of time. There will be a queue of planes waiting to take off and a priority queue of planes waiting to land.


There will be 3 classes:
Plane
Take-off queue


Priority queue


Your simulator will share some similarities to the movie theater simulator from the lecture notes (and the code is posted on Canvas). To make this project much simpler, I recommend studying that code and basing your code off of it.


When the user starts the simulation, let them decide the % chance that a plane will show up to land and the % chance that a plane will show up to take off each clock tick. Let them also decide how many clock ticks to run the simulation for. Recall that the simulation should run inside a for loop. Each loop iteration represents one unit of time (or clock tick). In each clock tick, you need to:



  1. Randomly decide if a plane should join the take-off queue, based on the percentage provided by the user.

  2. Randomly decide if a plane should join the landingpriority queue, based on the percentage provided by the user.


For this assignment, you will create a Plane class. Any Plane object joining the landing priority queue should have a random amount of remaining fuel assigned to it. This should range from about 5 to 15 time-units of fuel. Planes with less fuel upon arrival have a higher priority than planes with more fuel. Note: Your Plane class needs to implement Comparable. When a Plane leaves the priority queue and begins to land, determine how long it had been in the queue. If it was in the queue for longer than the fuel it had upon arrival, it crashes. A crashed plane doesn't count as a landed plane.


Each plane has a "transaction time" (i.e. how long it takes for a plane to land or take off). When a plane object is created, give it a random transaction time between 1 and 3. While a plane is landing or taking off, the runway is considered in use, and no other plane is allowed on the runway. When the runway is done being used, the landing priority queue is checked. If it contains any planes, the next one is selected to land. If there are no planes in the landing queue, the next plane in the take off queue may do so.


Record interesting statistics from your simulation and print them to the console. For example:



  1. What is the average time spent waiting for take off?

  2. What is the longest time spent waiting for take off?

  3. What is the average time spent waiting to land?

  4. What is the longest time spent waiting to land?

  5. How many planes crashed?

  6. How many planes total took off and landed during the simulation?


If you do not like the results you are getting (i.e. some planes crashed, no planes were able to take off, etc) feel free to tweak your numbers until the results are more realistic.


For the landing priority queue, use the priority queue you created in part 1.


For the take off queue, you may use the ArrayQueue code developed in class.


The code below is the priority queue from part 1.


public final class LinkedPriorityQueue> implements PriorityQueueInterface {     private Node firstNode;     private int size;     int firstPosition = 1;      public LinkedPriorityQueue()     {         firstNode = null;         size = 0;     }      @Override     public T remove()     {         T result = firstNode.data;
// Save entry to be removed


firstNode = firstNode.next; size--; return result; } @Override public void add (T newEntry) { Node newNode = new Node(newEntry); Node currentNode = firstNode; Node nodeBefore = null; while ((currentNode != null) && (newEntry.compareTo(currentNode.data) >= 0)) { nodeBefore = currentNode; currentNode = currentNode.next; } if (isEmpty() || (nodeBefore == null))
// Add at beginning


{ newNode.next = firstNode; firstNode = newNode; } else
// Add after nodeBefore


{ newNode.next = nodeBefore.next; nodeBefore.next = newNode; } size++; } @Override public boolean isEmpty() { if (size == 0) { return true; } else { return false; } } @Override public T peek() { for (int c = 1; c
//c for counter


{ firstNode = firstNode.next; } return firstNode.data; } @Override public void clear() { firstNode = null; size = 0; } @Override public int getSize() { return size; } private class Node { private T data; private Node next; private Node(T d) { data = d; next = null; } } public String toString() { StringBuilder sb = new StringBuilder(); for (Node i = firstNode; i != null; i = i.next) { sb.append(i.data).append(" "); } return sb.toString(); } }

For the take off queue, you may use the ArrayQueue code developed in class.


Create TakeOffQueue.java based of from the code below.


public class ArrayQueue< t=""> implements QueueInterface< t="">
{
private T[] entries; // circular array of the queue's entries with one unused index
private int frontIndex, backIndex;
private static final int DEFAULT_CAPACITY = 50;
private static final int MAX_CAPACITY = 10000;
public ArrayQueue()
{
this(DEFAULT_CAPACITY);
}
public ArrayQueue( int initialCapacity)
{
@SuppressWarnings ("unchecked")
T[] tempQueue = ( T[]) new Object[initialCapacity + 1];
entries = tempQueue;
frontIndex = 0;
backIndex = initialCapacity;
}
// methods go here
}

Answered 1 days AfterApr 10, 2022

Answer To: For this assignment, you will be programming an airport simulator. The airport has one runway, and a...

Anandkumar answered on Apr 11 2022
103 Votes
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here