Complete the run method. Each loop of the run() method represents one tick of time. The method
Fantastic news! We've Found the answer you've been seeking!
Question:
Complete the run method. Each loop of the run() method represents one tick of time. The method should:
- Advance the time by one "tick"
- Find all patients in the treatment room who have completed their current treatment and discharge them (remove them from the treatment room). For debugging, it is helpful to print a message for each patient when they are discharged: UI.println(time+ ": Discharge: " + p);
- Process one time tick for each patient currently being treated, or waiting in the waiting room.
- Move patients from the waiting room to the treatment room if there is space.
profile-image Time remaining: 00 : 06 : 43 Computer Science Complete the run method. Each loop of the run() method represents one tick of time. The method should: Advance the time by one "tick" Find all patients in the treatment room who have completed their current treatment and discharge them (remove them from the treatment room). For debugging, it is helpful to print a message for each patient when they are discharged: UI.println(time+ ": Discharge: " + p); Process one time tick for each patient currently being treated, or waiting in the waiting room. Move patients from the waiting room to the treatment room if there is space. -------------// Code //------------- public void run() { if (running) { return; } // don't start simulation if already running one! running = true; while (running) { // each time step, check whether the simulation should pause. // Hint: if you are stepping through a set, you can't remove // items from the set inside the loop! // If you need to remove items, you can add the items to a // temporary list, and after the loop is done, remove all // the items on the temporary list from the set. /*# YOUR CODE HERE */ // Get any new patient that has arrived and add them to the waiting room if (time == 1 || Math.random() < 1.0 / arrivalInterval) { Patient newPatient = new Patient(time, randomPriority()); UI.println(time + ": Arrived: " + newPatient); waitingRoom.offer(newPatient); } redraw(); UI.sleep(delay); } // paused, so report current statistics reportStatistics(); }
Related Book For
Legal Research Analysis and Writing
ISBN: 978-1305948372
4th edition
Authors: William H. Putman, Jennifer Albright
Posted Date: