Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In this assignment, you are required to write a menu-driven Java program that allows the user to add patients to a priority queue, display the

In this assignment, you are required to write a menu-driven Java program that allows the user to add patients to a priority queue, display the next patient (and remove him/her from the queue), show a list of all patients currently waiting for treatment, and exit the program. The program should simulate the scheduling of patients in a clinic. Use the attached Patient class provided along with this assignment. The focus is to apply the Java Collections Framework.

public class Patient{ //attributes private String name; private int order; //order of arrival private int emergency; //1 is normal, 5 is life-and-death situation //constructor public Patient(int order, String name, int priority) { this.order = order; this.name = name; this.emergency = priority; } //getters and setters public int getOrder() { return order; } public void setOrder(int order) { this.order = order; } public String getName() { return name; } public void setName(String name) { this.name = name; } public int getEmergency() { return emergency; } public void setEmergency(int emergency) { this.emergency = emergency; } public String toString() { return name; } } 

Your program should schedule patients in the queue according to the emergency of their cases from 1 to 5 (the higher the value, the higher the priority). If two patients have the same emergency value, use their order of arrival to set their priority (the lower the order, the higher the priority). It is up to you to have the Patient class implement either Comparable or Comparator. Create a class PatientManager that has an attribute named waitingList of the type PriorityQueue and a public method, start(). When start is called, it should display the following menu of choices to the user, and then ask the user to enter a choice from 1 to 4: Here is a description of each choice:

(1) Ask the user for the patients name and the emergency from 1 to 5 (1 = low, and 5 = lifeand-death). Your program should create an instance of Patient using the entered data and add it to the priority queue. Note that your program should not ask the user for the value of the patients order of arrival. Instead, it should use a counter that is automatically incremented whenever a patient is added to the queue.

(2) Display the name of the next patient in the priority queue and remove him/her from the queue.

(3) Display the full list of all patients that are still in the queue.

(4) End the program. Make sure your PatientManager class is robust. It should not crash when a user enters invalid value. Instead, it should display an error message followed by an action depending on the type of error (see the sample run below). Test your program by instantiating your PatientManager class in a main method and calling the start method. Note: Add more helper methods and attributes as needed to the PatientManager class.

Sample run

image text in transcribed

(1) New Patient. (2) Next Patient. (3) Waiting List. (4) Exit. Choose an item from the menu: 8 (x) Wrong choice. Choose an item from the menu: two (x) Wrong choice. Choose an item from the menu: 2 No more patients. Choose an item from the menu 3 No patients in the list. Choose an item from the menu: 1 Enter patient's name Abdallah Enter emergency [1 (low) to 5 (life-and-death)]: 8 (x) Wrong value. Try again: critical (x) Wrong value. Try again: 3 Patient added to the waiting list Choose an item from the menu: 1 Enter patient's name John Enter emergency [1 (low) to 5 (life-and-death) J: 4 Patient added to the waiting list. Choose an item from the menu: 3 Waiting list includes: John Abdallah Choose an item from the menu: 1 Enter patient's name Lili Enter emergency [1 (low) to 5 (life-and-death)]: 4 Patient added to the waiting list. Choose an item from the menu: 3 Waiting list includes: John Lili Abdallah Choose an item from the menu: 2 John is treated. Choose an item from the menu: 2 Lili is treated. Choose an item from the menu: 2 Abdallah is treated. Choose an item from the menu: 2 No more patients. Choose an item from the menu: 4 Program terminated. Good bye

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

DNA Databases

Authors: Stefan Kiesbye

1st Edition

0737758910, 978-0737758917

More Books

Students also viewed these Databases questions

Question

LO1 Summarize the organizations strategic planning process.

Answered: 1 week ago