Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

'Suppose there is a hospital with a waiting room filled with several patients. Patients are prioritized based on how severe their casualities are. For instance,

'Suppose there is a hospital with a waiting room filled with several patients. Patients are prioritized based on how severe their casualities are. For instance, car crash andgun shot patients are priority level 1, so they go straight to the front of the queue. Patients with heavy chest pain or mild heart attacks are priority level 2, and so on. Create a hospital that manages patients in a list. Implement it using the LinkedList API. (You may import ArrayList or List, but please do not import any other packages.) See Base_A11Q2.java for a starting place. In particular, see the HospitalADT interface which contains a description of the methods required in the to do list. Create a Patient class that implements Comparable and contains the name of the patient, the casualty of the patient, and the priority level. Make getters and a compareTo method that passes in another Patient and compares the priority levels of the patients. This method should compare the priority levels of the patients and return -1 if the first patient has a lower priority level than the second patient, 0 if the priority levels of the patients are equal, and 1 if the patient has a higher priority level than the second patient. All patients are added into the hospital list. The highest priority task in a to do list is the task with the lowest priority level. When removing patients, your hospital list should return the lowest priority patient. Patients should be removed from the queue when a doctor lets each patient in for examination. The attached file (Base_HW11Q2.java) already contains a driver that creates three Patient objects, adds them to a hospital list, and removes/displays them one by one.

image text in transcribed

import java.util.LinkedList; public class Base_HW11Q2 { static class Patient implements Comparable { //TODO: complete class } static interface HospitalADT { /** * Adds one patient to the hospital. * @param p the patient to be added to the hospital. */ public void add(Patient p); /** * Removes and returns the highest priority patient in the hospital. * @return the highest priority patient in the hospital. */ public Patient remove(); /** * Returns true if this hospital contains no patients. * @return true if this hospital is empty. */ public boolean isEmpty(); /** * Returns the number of patients in this hospital. * @return the integer representation of the size of the hospital. */ public int size(); } static class Hospital implements HospitalADT { //TODO: complete class } public static void main(String[] args) { Hospital hospital = new Hospital(); Patient p1 = new Patient("Martha Reynolds", "heavy chest pain", 2); Patient p2 = new Patient("Dennis Johnson", "ear ache", 3); Patient p3 = new Patient("John Smith", "car crash", 1); hospital.add(p1); hospital.add(p2); hospital.add(p3); System.out.println(hospital.remove()); System.out.println(hospital.remove()); System.out.println(hospital.remove()); } } 
output SER200 HW11 (run) Name John Smith Casualty car crash priority level of patient 1 HName: Martha Reynolds Casualty: heavy chest pain Priority Level of patient 2) HName: Dennis Johnson Casualty: ear ache Priority Level of Patient 3

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

Next Generation Databases NoSQLand Big Data

Authors: Guy Harrison

1st Edition

1484213300, 978-1484213308

More Books

Students also viewed these Databases questions

Question

How do modern Dashboards differ from earlier implementations?

Answered: 1 week ago