Below is the Java code for implementing this functionality using PriorityQueue available in Java.util Package.
The main important thing in this is, i created a comparator that compares the priorites while storing and retrieving from the queue.
Please add the below files in your editor and test. Execute the PatientPriorityQueueExample program which is having the main method.
1. Patient.java -----> This file is the value object store patient details.
2. TriageCodeComparator.java ---> compares the patient triagecode while storing and retreiving from the queue.
3. TriageCodeSimulator.java ---> have the actual methods like add/remove/isEmpty
4. PatientPriorityQueueExample.java ----> Used for testing the queue.
Patient.java
package javaapplication1;
public class Patient {
private String fName;
private String lName;
private String triageCode;
private int priority;
public Patient() {
}
public Patient(String fName, String lName, String triageCode)
{
this.fName = fName;
this.lName = lName;
this.triageCode = triageCode;
switch (triageCode) {
case "AL":
case "HA":
case "ST":
this.setPriority(1);
break;
case "BL":
case "KS":
case "IW":
case "OT":
this.setPriority(2);
break;
case "HN":
this.setPriority(3);
break;
}
}
public String getfName() {
return fName;
}
public void setfName(String fName) {
this.fName = fName;
}
public String getlName() {
return lName;
}
public void setlName(String lName) {
this.lName = lName;
}
public String getTriageCode() {
return triageCode;
}
public void setTriageCode(String triageCode) {
this.triageCode = triageCode;
}
public int getPriority() {
return priority;
}
public void setPriority(int priority) {
this.priority = priority;
}
}

TriageCodeComparator.java
package javaapplication1;
import java.util.Comparator;
/**
*
* @author Murthy
*/
public class TriageCodeComparator implements
Comparator<Patient> {
@Override
public int compare(Patient p1, Patient p2) {
return (int) (p1.getPriority() - p2.getPriority());
}
}

TriageCodeSimulator.java
package javaapplication1;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Scanner;
public class TriagecodeSimulator {
Comparator triageCodeComparator = new TriageCodeComparator();
Queue<Patient> patientPriorityQueue = new
PriorityQueue<>(7, triageCodeComparator);
//utility method to add random data to Queue
public void add() throws FileNotFoundException {
File file = new File("D:\\test.txt");
Scanner sc = new Scanner(file);
while (sc.hasNextLine()) {
String patientData = sc.nextLine();
String tokens[] = patientData.split(" ");
patientPriorityQueue.add(new Patient(tokens[0], tokens[1],
tokens[2]));
}
}
//utility method to poll data from queue
public Patient remove() {
Patient patient = patientPriorityQueue.remove();
System.out.println("returning patient with FName =" +
patient.getfName() + " & TriageCode = " +
patient.getTriageCode());
return patient;
}
public boolean isEmpty(){
return patientPriorityQueue.isEmpty();
}
}

PatientPriorityQueueExample.java
package javaapplication1;
import java.io.FileNotFoundException;
public class PatientPriorityQueueExample {
public static void main(String[] args) throws
FileNotFoundException {
TriagecodeSimulator simulator = new TriagecodeSimulator();
simulator.add();
while( !simulator.isEmpty()){
simulator.remove();
}
}
}

Output :
run:
returning patient with FName =Surya & TriageCode = HA
returning patient with FName =Vijaya & TriageCode = KS
returning patient with FName =Ramani & TriageCode = KS
returning patient with FName =Narayana & TriageCode = BL
returning patient with FName =Padmini & TriageCode = HN
BUILD SUCCESSFUL (total time: 0 seconds)

My Input file is stored in D:\ drive with the name as test.txt. Its contents is.
Surya Murthy HA
Narayana Murthy BL
Padmini Murthy HN
Ramani Murthy KS
Vijaya Murthy KS
Code in Java please For this assignment you are to write a simulator that will simulate...