Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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(); }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Legal Research Analysis and Writing

Authors: William H. Putman, Jennifer Albright

4th edition

1305948378, 9781337469531 , 978-1305948372

More Books

Students also viewed these Programming questions