Programming Language Java Question 2 Simulating Hospital Emergency Room Priority Queue Imp Q29581462

Programming Language is Java

Question 2: Simulating a Hospital Emergency Room with a PriorityQueue
You will implement a priority queue and use it to simulate ahospital emergency room. Input will be a list of people
arriving at the ER, read from a txt file. Output will be a list ofevents in the ER, where each event is either (i) a
patient arriving or (ii) the doctor completing a treatment andbecoming available or (iii) a patient being called in to
see the doctor.
The Patient class
Create a Patient class as follows:
• Each patient will have a patient number (integer). For theemergency room simulation, the patient number
will be the order they arrive at the emergency room, beginning with1.
• Each patient will have an urgency (integer between 1 and 10),where 1 is low priority and 10 is high priority.
• Each patient will have a treatment time (an integer representinga number of minutes). This represents the
amount of time that the doctor is occupied treating thatpatient.
• Include public methods to get the patient number, urgency, andtreatment time.
• Write a print method to use while debugging. Leave this method inyour submitted code. Following good
coding practices, any methods outside the Patient class that needto print patient information should not call
this print method. Instead, they should use the get methods to viewdata, and print the data returned by the
get methods.
The Priority Queue class
You will use a priority queue of patients to determine the orderthat patients are seen by the doctor. Before writing
the code to simulate the emergency room, you should implement thepriority queue as below. Remember to test the
queue as you develop it.
• Your queue will be implemented as an array of Patients.
• The public methods for your queue will be enqueue (add a new itemto the queue), dequeue (remove an item
from the queue), front (peek at the item at the front of thequeue), and isEmpty.
• The highest priority patients should be located at the front ofthe queue.
• The isEmpty method will return true if the queue contains noitems and false otherwise.
• The enqueue method will insert a patient into the queue so thatthe highest priority patient is at the front
of the queue (i.e. you will pass enqueue a Patient object). If thequeue is full, double the size of the array and
add the new patient, so that there is never a maximum number ofpatients that could be waiting.
• The dequeue method will return the patient at the front of thequeue (i.e. dequeue will return a Patient
object), and will remove that patient from the queue.
• The front method will return the patient at the front of thequeue but will leave that patient in the queue.
Write a print method to use while debugging. Leave this method inyour submitted code. Following good
coding practices, any methods outside the priority queue class thatneed to print patient information should
not call this print method. Instead, they should use the Patientget methods to view data, and print the data
returned by the get methods.
The Emergency Room Simulation
Simulate an emergency room with one doctor. As patients arrive,they are placed in a priority queue according to
the urgency of their case. When the doctor is available (e.g. whena treatment ends), the next patient in the queue
will be called in.
• The file patients.txt lists the patients, one per line. Each linecontains the arrival time, the urgency, and
the required time with the doctor. The integers are separated by asingle space.
• Assume that the arrivals file is in order by time of arrival.This means you should read in only one arrival at
a time.
• When the doctor is free, and there is a patient waiting, thepatient at the front of the queue will be called in
for treatment.
• Print a statement for each event (when a patient arrives, when apatient is called in to the doctor, when the
doctor is available). Follow the format in the sample outputbelow.
Sample input:
2 4 15
5 3 5
7 9 12
14 5 9
131 2 5
138 3 10
Sample output:
Doctor is available at time = 0
Patient 1 arrived at time = 2 with urgency = 4 and treatment time =15.
Doctor is available at time = 2
Patient 1 in for treatment at time = 2 with urgency = 4 andtreatment time = 15.
Patient 2 arrived at time = 5 with urgency = 3 and treatment time =5.
Patient 3 arrived at time = 7 with urgency = 9 and treatment time =12.
Patient 4 arrived at time = 14 with urgency = 5 and treatment time= 9.
Doctor is available at time = 17
Patient 3 in for treatment at time = 17 with urgency = 9 andtreatment time = 12.
Doctor is available at time = 29
Patient 4 in for treatment at time = 29 with urgency = 5 andtreatment time = 9.
Doctor is available at time = 38
Patient 2 in for treatment at time = 38 with urgency = 3 andtreatment time = 5.
Doctor is available at time = 43
Patient 5 arrived at time = 131 with urgency = 2 and treatment time= 5.
Doctor is available at time = 131
Patient 5 in for treatment at time = 131 with urgency = 2 andtreatment time = 5.
Doctor is available at time = 136
Patient 6 arrived at time = 138 with urgency = 3 and treatment time= 10.
Doctor is available at time = 138
Patient 6 in for treatment at time = 138 with urgency = 3 andtreatment time = 10.
Doctor is available at time = 148
Additional Notes
• You may assume that the input file will be free of errors. Eachline in the file will represent one patient and
consist of three integers, separated by a space. The urgency willalways be a valid integer between 1 and 10.
The treatment time will be a valid positive integer.

You may assume that there will be a maximum of one arrival perminute. That is, no two patients listed in
the input file will have the same arrival time.

Patients.txt

2 4 155 3 57 9 1214 5 9131 2 5138 3 10150 4 6152 3 7 156 8 22159 1 3161 2 8164 5 20165 6 25169 2 4173 9 24176 6 12177 7 18250 2 5270 3 10320 8 20324 4 14328 6 17337 2 5339 9 15

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply