please help me with this java problem. using java write an interactive program that will monitor the ?ow of patients in a large hospital. The program should account for patients who check in and out of the hospital and should allow access to information about a given patient. In addition, the program should manage the scheduling of three operating rooms. Doctors make a request that includes a patient’s name and a priority value between 1 and 10 that re?ects the urgency of the operation. Patients are chosen for the operating room by priority value, and patients with the same priority are served on a ?rst-come, ?rst-served basis. The user should use either one-letter or one-word commands to control the program. As you design your solution, try to identify the essential operations (excuse the pun) that you must perform on the data, and only then choose an appropriate data structure for implementation. This approach will allow you to maintain the wall between the main part of the program and the implementations.
This question demands for proper implementation of priority queue.
In priority queue job with higher priority is scheduled first and if two jobs have same priority then then first come first serve basis.
Code is given as below
//Patient with low priority value will be operated first i.e. priority 1 is higher than 2 whenever a remove is called priority basis patient is removed and detail sent to doctor
import java.util.Scanner;
/** class Task **/
class Patient
{
String name;
int priority;
/** Constructor **/
public Patient(String name, int priority)
{
this.name = name;
this.priority = priority;
}
/** toString() **/
public String toString()
{
return "Patient Name : "+ name +"\nPriority : "+ priority;
}
}
class PriorityQueue
{
private Patient[] heap;
private int heapSize, capacity;
/** Constructor **/
public PriorityQueue(int capacity)
{
this.capacity = capacity + 1;
heap = new Patient[this.capacity];
heapSize = 0;
}
/** function to clear **/
public void clear()
{
heap = new Patient[capacity];
heapSize = 0;
}
/** function to check if empty **/
public boolean isEmpty()
{
return heapSize == 0;
}
/** function to check if full **/
public boolean isFull()
{
return heapSize == capacity - 1;
}
/** function to get Size **/
public int size()
{
return heapSize;
}
/** function to insert task **/
public void insert(String job, int priority)
{
Patient newJob = new Patient(job, priority);
heap[++heapSize] = newJob;
int pos = heapSize;
while (pos != 1 && newJob.priority >
heap[pos/2].priority)
{
heap[pos] = heap[pos/2];
pos /=2;
}
heap[pos] = newJob;
}
/** function to remove task **/
public Patient remove()
{
int parent, child;
Patient item, temp;
if (isEmpty() )
{
System.out.println("Heap is empty");
return null;
}
item = heap[1];
temp = heap[heapSize--];
parent = 1;
child = 2;
while (child <= heapSize)
{
if (child < heapSize && heap[child].priority <
heap[child + 1].priority)
child++;
if (temp.priority >= heap[child].priority)
break;
heap[parent] = heap[child];
parent = child;
child *= 2;
}
heap[parent] = temp;
return item;
}
}
/** Class Hospital with main function execution start from here
**/
public class Hospital
{
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
System.out.println("Hospital checkin and checkout and operation
scheduling system\n");
System.out.println("Enter number of patients ");
PriorityQueue pq = new PriorityQueue(scan.nextInt() );
char ch;
/* Perform Priority Queue operations */
do
{
System.out.println("\nPriority Queue Operations\n");
System.out.println("1. Add a Patient or check in");
System.out.println("2. remove a patient or Send patient to
doctor");
System.out.println("3. check empty");
System.out.println("4. check full");
System.out.println("5. clear");
System.out.println("6. Get number of patients");
int choice = scan.nextInt();
switch (choice)
{
case 1 :
System.out.println("Enter Patient name and priority");
pq.insert(scan.next(), scan.nextInt() );
break;
case 2 :
System.out.println("\nPatient remove or send next operationg
patient to doctor \n\n"+ pq.remove());
break;
case 3 :
System.out.println("\nEmpty Status : "+ pq.isEmpty() );
break;
case 4 :
System.out.println("\nFull Status : "+ pq.isFull() );
break;
case 5 :
System.out.println("\nAll patient removed");
pq.clear();
break;
case 6 :
System.out.println("\nTotal number of patients = "+ pq.size()
);
break;
default :
System.out.println("Wrong Entry \n ");
break;
}
System.out.println("\nDo you want to continue (Type y or n)
\n");
ch = scan.next().charAt(0);
} while (ch == 'Y'|| ch == 'y');
}
}
please help me with this java problem. using java write an interactive program that will monitor the ?ow of patients in a large hospital. The program should account for patients who check in and out o...