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 = new PriorityQueue<>(10,new ComparePatient());

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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!