Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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.

1) 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.

2) 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).

3) 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));

PriorityQueue patientQueue1 = new PriorityQueue<>(10,new ComparePatient());

patientQueue1.add(new Patient(1, "Patient1", false)); patientQueue1.add(new Patient(2, "Patient2", false)); patientQueue1.add(new Patient(5, "Patient5", true)); patientQueue1.add(new Patient(4, "Patient4", false)); patientQueue1.add(new Patient(3, "Patient3", true));

The order in your priority queue should be similar to the following output

Doctor's waiting for patients : Patient3 <-- Patient5 <-- Patient1 <-- Patient2 <-- Patient4

The order in your priority queue1 should be similar to the following output

Doctor's waiting for patients : Patient3 <-- Patient5 <-- Patient1 <-- Patient2 <-- Patient4

Q3 : Using the Set interface

1. Write the Instructor class that holds information about an instructor( LastName, FirstName, OfficeNo). Add the instance variables, a constructor, the toString() method then write a class that stores several Instructor objects in a HashSet. The class should be able to display all the instructors in the set, and allow the user to search for an instructor. Demonstrate the class in an application.

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

Students also viewed these Databases questions