Question: Lab- Java Priority Queue In this lab you will demonstrate the use of Priority Queue in a real world example. Patients waiting to be treated
Lab- Java Priority Queue
In this lab you will demonstrate the use of Priority Queue in a real world example.
Patients waiting to be treated by a doctor are selected by checking if it is an emergency case or not.
First, you need to create a class named Patient with idNumber(int), name(String) and emergencyCase (Boolean) as the class attributes.
Add a constructor with three parameters and three get Methods to return each attribute data.
Next, create another class named ComparePatient that implements the Comparator interface.
Implement the compare() method to provide an order for two patients based on their emergencyCase data. In case both patients have the same value of emergencyCase, then compare their idNumber (you can use the compareTo() method of Integer class to compare the idNumbers).
Test your priority queue with the following patients.
PriorityQueue
patientQueue.add(new Patient(1, "Patient1", false));
patientQueue.add(new Patient(2, "Patient2", false));
patientQueue.add(new Patient(3, "Patient3", true));
patientQueue.add(new Patient(4, "Patient4", false));
patientQueue.add(new Patient(5, "Patient5", true));
The order in your priority queue should be similar to the following output
Doctor's waiting for patients : Patient3 <-- Patient5 <-- Patient1 <-- Patient2 <-- Patient4
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
