Question

Week 7 Exercise 5 Both source code and screen shot of the output are required to...

Week 7 Exercise 5

Week 7 Exercise 5 Both source code and screen sho

Both source code and screen shot of the output are required to verify that the program is working correctly. Thanks in advance for both your time and effort.

Correct/Fix the following source code and display the output. Reupload the working code and image of the output.




public class AirportSimulation {

    public final static int SIMULATION_TIME = 100;  // the total number of minutes for the simulation
                
        private Queue<Plane> takeOffQ;        // the queue of planes waiting to takeoff
    private Queue<Plane> landingQ;        // the queue of planes waiting to land
        private LinkedList<Plane> allPlanes;  // all the active planes in the simulation
                
        private BooleanSource wantsToTakeOff; // a boolean generator to help create new planes
        private BooleanSource wantsToLand;    // a boolean generator to help create new planes
                
        private Runway runway; // the runway object
        
        // The following variables are used to collect stats on the simulation
        int totalTakeOffWait;  // total time planes have waited to takeoff
        int totalLandingWait;  // total time planes have waited to land
                
        int totalPlanesLanded; // total number of planes that have landed
        int totalPlanesTakenOff;  // total number of planes that have taken off
        
        int avgLandingQueueSize;
        int avgTakeOffQueueSize;
        int avgAllPlanesQueueSize;
        int avgCounter;
        int avgBusyCounter;
        
        
        // the constructor
    // Place the constructor here for Checkpoint #3.
        public AirportSimulation ()
        {
                wantsToLand = new BooleanSource(0.25);
                wantsToTakeOff = new BooleanSource(0.1);
                
                runway = new Runway();
                
                takeOffQ = new LinkedList<Plane>();
                landingQ = new LinkedList<Plane>();
                allPlanes = new LinkedList<Plane>();
                
                totalTakeOffWait = 0;
                totalLandingWait = 0;
                
                totalPlanesLanded = 0;
                totalPlanesTakenOff = 0;
                
                avgLandingQueueSize = 0;
                avgTakeOffQueueSize = 0;
                avgAllPlanesQueueSize = 0;
                avgCounter = 0;
                avgBusyCounter = 0;
        }
   
   /* This is the driver method for the simulation.  It runs through the simulation
           updating the planes, runway and summary statistics 
        */
        public void run()
        {
                                
                for (int t=0; t<=SIMULATION_TIME; t++)
                {
                   // Check if a new plane wants to takeoff
                        if (wantsToTakeOff.query())
                        {
                           Plane p = new Plane();
                           takeOffQ.offer(p);
                       allPlanes.add(p);                
                        }
                        
                        // Check if a new plane wants to land
            // Place code here for checkpoint #3, to see if any planes
                        // want to land.  Hint: This code closely parallels checking
                        // if any planes want to take off.
                        if( wantsToLand.query() )
                        {
                                Plane p = new Plane();
                                landingQ.offer(p);
                                allPlanes.add(p);
                        }else
                        
                        // Process plane on the runway
                        if (runway.isClear())
                        {
                                // Place code here for Checkpoint #3.
                                // First check if any planes want to land, since landing
                                // takes priority over taking off.  If there is a plane that
                                // wants to land, 
                                // 1. remove it from the landingQ and assign it
                                //    to the runway, with the action of "Landing".
                                // 2. remove it from allPlanes.
                                // 3. Add its waitTime to totalLandingWait
                                // 4. Add 1 to totalPlanesLanded.
                                
                                // else if there is a plane waiting to take off:
                                // - take action appropriate to taking off.  This is
                                //   completely parallel to landing.
                                
                                // If planes want to land
                                if( landingQ.peek() != null )
                                {
                                        // remove from the landingQ and assign it
                                        Plane landingPlane = landingQ.poll();
                                        runway.assignPlane(landingPlane, PlaneAction.Landing);
                                        
                                        // remove from the allPlanes
                                        allPlanes.remove(landingPlane);
                                        
                                        // Add it's waitTime to the totalLandingWait
                                        totalLandingWait += landingPlane.getLandingTime();
                                        
                                        //Add 1 to totalPlanesLanded
                                        totalPlanesLanded++;
                                }
                                else if( takeOffQ.peek() != null )
                                {
                                        // remove from the landingQ and assign it
                                        Plane takeoffPlane = takeOffQ.poll();
                                        runway.assignPlane(takeoffPlane, PlaneAction.TakingOff);
                                        
                                        // remove from the allPlanes
                                        allPlanes.remove(takeoffPlane);
                                        
                                        // Add it's waitTime to the totalTakeOffWait
                                        totalTakeOffWait += takeoffPlane.getTakeOffTime();
                                        
                                        //Add 1 to planes taken off
                                        totalPlanesTakenOff++;
                                }       
                        }
                        else
                        {
                           runway.update();
                        }
                        
                        // Add to the wait time of all remaining planes
                        Iterator<Plane> it = allPlanes.iterator();
                        while (it.hasNext())
                        {
                            Plane p = it.next();
                                p.updateWaitTime (1);
                                avgBusyCounter++;
                        }
                        
                        avgLandingQueueSize += landingQ.size();
                        avgTakeOffQueueSize += takeOffQ.size();
                        avgAllPlanesQueueSize += allPlanes.size();
                        avgCounter++;
                }
        }
        
        /* This method prints a brief report summarizing statistics about the simulations */
        public void report ()
        {       
                System.out.println(totalPlanesLanded + " planes have landed.");
                System.out.println(totalPlanesTakenOff + " planes have taken off.");
                System.out.println(landingQ.size() + " planes still waiting to land.");
                System.out.println(takeOffQ.size() + " planes still waiting to takeoff.");
                
                System.out.println(1.0*totalTakeOffWait/SIMULATION_TIME + " average take off wait time.");
                System.out.println(1.0*totalLandingWait/SIMULATION_TIME + " average landing wait time."); 
                
                System.out.printf("Average size of the landingQ: %s\r\n", avgLandingQueueSize / avgCounter );
                System.out.printf("Average size of the takeOffQ: %s\r\n", avgTakeOffQueueSize / avgCounter );
                System.out.printf("Average size of the allPlanes: %s\r\n", avgAllPlanesQueueSize / avgCounter );
                System.out.printf("Percent Busy: %s\r\n", 1.0 - ((double)totalPlanesLanded + (double)totalPlanesTakenOff) / (double)avgCounter  );
                
        }
        
        
        public static void main (String [] args)
        {
            AirportSimulation sim = new AirportSimulation();
                sim.run();
                sim.report();
        }
}
0 0
Add a comment Improve this question Transcribed image text
Request Professional Answer

Request Answer!

We need at least 10 more requests to produce the answer.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the answer will be notified once they are available.
Know the answer?
Add Answer to:
Week 7 Exercise 5 Both source code and screen shot of the output are required to...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Similar Homework Help Questions
  • I am trying to make a linked list queue and I am trying to use the...

    I am trying to make a linked list queue and I am trying to use the display method I made just to see if its working but when I run it nothing is displayed please help. Also the newPlane boolean was made just so I can randomly decide if the plane is going to join the queue or not. public class PlaneSimulation { public static void main(String[] args) { int landTime = 2; int takeoffTime = 3; int avgArrivalInterval =...

  • NO ONE HAS PROVIDED THE CORRECT CODE TO PROVIDE THE GIVEN OUTPUT. PLEASE PROVIDE CODE THAT...

    NO ONE HAS PROVIDED THE CORRECT CODE TO PROVIDE THE GIVEN OUTPUT. PLEASE PROVIDE CODE THAT WOULD CAUSE THE HW1.java TO PRINT THE RIGHT DATA.!!! The LinkedList class implements both the List interface and the Stack interface, but several methods (listed below) are missing bodies. Write the code so it works correctly. You should submit one file, LinkedList.java. Do not change the interfaces. Do not change the public method headers. Do not rename the LinkedList class. None of your methods...

  • Hello! I have a problem in my code please I need help, I don't know How I can wright precondition, so I need help about assertion of pre_condition of peek. Java OOP Task is! Improve the circular a...

    Hello! I have a problem in my code please I need help, I don't know How I can wright precondition, so I need help about assertion of pre_condition of peek. Java OOP Task is! Improve the circular array implementation of the bounded queue by growing the elements array when the queue is full. Add assertions to check all preconditions of the methods of the bounded queue implementation. My code is! public class MessageQueue{ public MessageQueue(int capacity){ elements = new Message[capacity];...

  • in java coorect this code & screenshoot your output ---------------------------------------------------------------------- public class UNOGame {     /**...

    in java coorect this code & screenshoot your output ---------------------------------------------------------------------- public class UNOGame {     /**      * @param args the command line arguments      */         public static void main(String[] args) {       Scanner input=new Scanner(System.in);          Scanner input2=new Scanner(System.in);                             UNOCard c=new UNOCard ();                UNOCard D=new UNOCard ();                 Queue Q=new Queue();                           listplayer ll=new listplayer();                           System.out.println("Enter Players Name :\n Click STOP To Start Game..");        String Name = input.nextLine();...

  • Convert into pseudo-code for below code =============================== class Main {    public static void main(String args[])...

    Convert into pseudo-code for below code =============================== class Main {    public static void main(String args[])    {        Scanner s=new Scanner(System.in);        ScoresCircularDoubleLL score=new ScoresCircularDoubleLL();        while(true)        {            System.out.println("1--->Enter a number\n-1--->exit");            System.out.print("Enter your choice:");            int choice=s.nextInt();            if(choice!=-1)            {                System.out.print("Enter the score:");                int number=s.nextInt();                GameEntry entry=new GameEntry(number);   ...

  • Complete the code below, test cases to use are at the bottom package Labs; public class ResizingQ...

    Complete the code below, test cases to use are at the bottom package Labs; public class ResizingQueue { private final int INITIAL_SIZE = 10;   private int [] A = new int[INITIAL_SIZE]; // array to hold queue: front is always at Q[0] // and rear at A[next-1] int next = 0; // location of next available unused slot // interface methods public void enqueue(int key) { //TODO: push the key onto the back of the queue // YOUR CODE HERE! }...

  • JAVA Only Help on the sections that say Student provide code. The student Provide code has...

    JAVA Only Help on the sections that say Student provide code. The student Provide code has comments that i put to state what i need help with. import java.util.Scanner; public class TicTacToe {     private final int BOARDSIZE = 3; // size of the board     private enum Status { WIN, DRAW, CONTINUE }; // game states     private char[][] board; // board representation     private boolean firstPlayer; // whether it's player 1's move     private boolean gameOver; // whether...

  • Take the following code and add a joption pane to make it eaiser to read. Can...

    Take the following code and add a joption pane to make it eaiser to read. Can anyone tell me whats wrong with my code? It wont compile JAVA. import java.util.Scanner; import java.util.Queue; import java.util.LinkedList; class que { public static void main(String args[]) { int count=0,min=0,hr=0; String a; Scanner inp=new Scanner(System.in); Queue q=new LinkedList<>(); while(count<10) { System.out.println("Enter your name:"); a=inp.nextLine(); q.add(a); count=count+1; min=min+5; if(min>=60) { hr=hr+1; } System.out.println("You are "+count+" in the queue"); System.out.println("Average wait time is "+hr+" hours and "+min+"...

  • P1 is below package p6_linkedList; import java.util.*; public class LinkedList { public Node header; public LinkedList()...

    P1 is below package p6_linkedList; import java.util.*; public class LinkedList { public Node header; public LinkedList() { header = null; } public final Node Search(int key) { Node current = header; while (current != null && current.item != key) { current = current.link; } return current; } public final void Append(int newItem) { Node newNode = new Node(newItem); newNode.link = header; header = newNode; } public final Node Remove() { Node x = header; if (header != null) { header...

  • Design and implement a class Q that uses Q.java as a code base. The queue ADT...

    Design and implement a class Q that uses Q.java as a code base. The queue ADT must use class LinkedList from Oracle's Java class library and its underlying data structure (i.e. every Q object has-a (contains) class LinkedList object. class Q is not allowed to extend class LinkedList. The methods that are to be implemented are documented in Q.java. Method comment blocks are used to document the functionality of the class Q instance methods. The output of your program must...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT