Finish the project. Fill in all the areas of the code that have a TODO comment for the program to work properly. Implement a queue
Finish the project. Fill in all the areas of the code that have a TODO comment for the program to work properly.
Implement a queue using doubly linked nodes to simulate a simple airport with the following rules in place: There are 2 runways and only one airplane can take off any a certain turn. The airplanes alternate between runways - unless one runway is empty. Extra credit (10 points): Alternatively, you can implement a bit more complex logic by giving Runway 1 a higher priority, so 2 airplanes can take off consecutively, even if there is a plane waiting in Runway 2.
QueueInterface:
Airplane Class:
LinkedQueue Class:
Fill in the following a TODO areas to make the program work properly:
Second part of LinkedQueue:
QueueTestDriver Class:
Second part of QueueTestDriver class:
AirportSimulation class:
Fill in the following a TODO areas to make the program work properly:
Second part of AirportSimulation:
public interface QueueInterfaceT Inserts the specified elenent into this queue. public void enqueue(T ahj): /xt * Retrieves and remaves the head of this queue, or returns null if this queue is enpty public T dequeue): Retrieves, but daes nat renove, the head of this queue, ar returns null if this queue is enpty public T getFront); 14 *Checks if there are any clcnents in the qucuc *return true it, and only if, the queue is enpty public boolean isEmpty): * greturn apprapriate string representing the queue @override public String tostring); /xo* * Very simple Airplane class with airline and flight number information public class Airplane String airline int flightNumber public Airplane(String airline, int flightNumber) public String getAirline) public void setAirline(String airline) public int getFlightNumber() public void setFlightNumber(int flightNumber) @Override this.airline airline; this.flightNumberflightNumber; return airline; this.airline -airline; return flightNumber; this.flightNumber flightNumber; public String toString) return "Airplane lairline-"airline ", flightNumber-"flightNumber "]" a * A simple implementatlan af the queue ADT using nested Node class and a daubly linked list *@paran T public class LinkedQueueT implenents QueueInterfacecT t Node front; Node back; public LinkedQueue) t front null; back null; public void cnqucue T obj) if (1sEmpty)) Nade node = new Node (obj, null, null); frant nade; back nodc; Nade nade-new Node obj, null, back) hark.setNext(node back nodc: public T dequeue() { TO0O Implement dequeue t Now we have to be carefut to nake sure we think of the various scenarios // and update the prev and next links accordingly return null: public T getFrant) TO0O Implenent getFront return null: public boolean isEmpty TODO Implement isEnpty return false; verride public String toString) TOD0 Implement tostring nethod return ff Nested class Nade f For queues, it is helpful to inplenent this as a doubly linked list Thereforc, we kecp track of both ncxt and previous nodes private class Node T data Node next; Node prev; t Constructor for inner class Node NodelT data, Nade next, Node prev t this.data data; this. next = next ; this.prevprev /1 Constructor for inner class Node Node (T data, Node next, Node prey) f this.data - data; this.next = next; this.erex Rrev: // Setters&Getters for inne r class Node public T getData) public void setData(T data) public Node getNext) public void setNext (Node next) public Node getPrey) public void setPrev (Node prev) return data; this.data data; return next; this.nextnext: return pRY this.pr public static void testCase2) runway2.enqueue (plane1); runway2.enqueue (plane2) runway2.enqueue (plane3) runway2.enqueue (plane4); runway2.enqueue (plane5); runway2.enqueue (plane6); public static void testCase3 ) runway1.enqueue (plane1); runway1.enqueue (plane2); runway1.enqueue (plane3); runway2.enqueue (plane4) runway2.enqueue (plane5); runway2.enqueue (plane6); public static void testCase4 runway1.enqueue (plane1); runway1.enqueue (plane2) runway1.enqueue(plane3); runway1.enqueue (plane4); runway1.enqueue (plane5); runway2.enqueue (plane6); public interface QueueInterfaceT Inserts the specified elenent into this queue. public void enqueue(T ahj): /xt * Retrieves and remaves the head of this queue, or returns null if this queue is enpty public T dequeue): Retrieves, but daes nat renove, the head of this queue, ar returns null if this queue is enpty public T getFront); 14 *Checks if there are any clcnents in the qucuc *return true it, and only if, the queue is enpty public boolean isEmpty): * greturn apprapriate string representing the queue @override public String tostring); /xo* * Very simple Airplane class with airline and flight number information public class Airplane String airline int flightNumber public Airplane(String airline, int flightNumber) public String getAirline) public void setAirline(String airline) public int getFlightNumber() public void setFlightNumber(int flightNumber) @Override this.airline airline; this.flightNumberflightNumber; return airline; this.airline -airline; return flightNumber; this.flightNumber flightNumber; public String toString) return "Airplane lairline-"airline ", flightNumber-"flightNumber "]" a * A simple implementatlan af the queue ADT using nested Node class and a daubly linked list *@paran T public class LinkedQueueT implenents QueueInterfacecT t Node front; Node back; public LinkedQueue) t front null; back null; public void cnqucue T obj) if (1sEmpty)) Nade node = new Node (obj, null, null); frant nade; back nodc; Nade nade-new Node obj, null, back) hark.setNext(node back nodc: public T dequeue() { TO0O Implement dequeue t Now we have to be carefut to nake sure we think of the various scenarios // and update the prev and next links accordingly return null: public T getFrant) TO0O Implenent getFront return null: public boolean isEmpty TODO Implement isEnpty return false; verride public String toString) TOD0 Implement tostring nethod return ff Nested class Nade f For queues, it is helpful to inplenent this as a doubly linked list Thereforc, we kecp track of both ncxt and previous nodes private class Node T data Node next; Node prev; t Constructor for inner class Node NodelT data, Nade next, Node prev t this.data data; this. next = next ; this.prevprev /1 Constructor for inner class Node Node (T data, Node next, Node prey) f this.data - data; this.next = next; this.erex Rrev: // Setters&Getters for inne r class Node public T getData) public void setData(T data) public Node getNext) public void setNext (Node next) public Node getPrey) public void setPrev (Node prev) return data; this.data data; return next; this.nextnext: return pRY this.pr public static void testCase2) runway2.enqueue (plane1); runway2.enqueue (plane2) runway2.enqueue (plane3) runway2.enqueue (plane4); runway2.enqueue (plane5); runway2.enqueue (plane6); public static void testCase3 ) runway1.enqueue (plane1); runway1.enqueue (plane2); runway1.enqueue (plane3); runway2.enqueue (plane4) runway2.enqueue (plane5); runway2.enqueue (plane6); public static void testCase4 runway1.enqueue (plane1); runway1.enqueue (plane2) runway1.enqueue(plane3); runway1.enqueue (plane4); runway1.enqueue (plane5); runway2.enqueue (plane6)Step by Step Solution
There are 3 Steps involved in it
Step: 1
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started