Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

PLEASE follow sample output Focus: Java Collection Framework In this assignment,

ID: 3801261 • Letter: P

Question

PLEASE follow sample output

Focus: Java Collection Framework In this assignment, you are required to write a menu-driven Java program that allows the user to add patients to a priority queue, displaythe 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 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 Patient 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: (1) New Patien 2) Next Patient (3) Waiting List (4) Exit Here is a description of each choice: (1) Ask the user for the patient's name and the emergency from 1 to 5 (1 ow, and 5 fe and-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 askthe user for the value of the patient's 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

Explanation / Answer

package patient;

import java.util.Iterator;
import java.util.PriorityQueue;
import java.util.Scanner;

public class PatientManager {
   PriorityQueue<Patient> waitingList;
   String name;
   int priority;
   int choice;
   public void start() {
       System.out.println("------------------------------------");
       System.out.println("(1) New Patient.");
       System.out.println("(2) Next Patient.");
       System.out.println("(3) Waiting List.");
       System.out.println("(4) Exit.");
       System.out.println("------------------------------------");
  
       Scanner scan = new Scanner(System.in);
       System.out.println("Please enter your choice according to above 1 to 4 options :");
      
       if(choice <= 0 && choice > 4){
           choice = scan.nextInt();
       }
       else{
           System.out.println("Wrong choice :");
       }
       switch (choice) {
       case 1:
           System.out.println("Enter patient's name :");
           name = scan.next();
           System.out.println("Enter emergency [1 (low) to 5 (life and death)] :");
           priority = scan.nextInt();
           int count = 0;
           Patient patient = new Patient(count, name, priority);
           waitingList = new PriorityQueue<Patient>();
           waitingList.add(patient);
           count++;
           System.out.println("Patient added to the waiting list");
           break;
       case 2:
           System.out.println(waitingList);
           break;
       case 3:
           Iterator<Patient> iterator = waitingList.iterator();
           while (iterator.hasNext()) {
               System.out.println("Waiting List include :" + iterator.next());
           }
           break;
       case 4:
           System.exit(0);
           break;
       default:
           System.out.println("Wrong value : Try again");
       }
       scan.close();
   }
   public static void main(String[] args) {
       PatientManager manager = new PatientManager();
       manager.start();
   }

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote