Write Triage. Patients arrive with a severity from 1 (most urgent) to 5. Commands until the end of input:
arrive NAME SEVERITY;next— treat the most urgent waiting patient; among equal severities, the one who arrived first (nobody is waitingif the queue is empty). Also report how many patients who arrived earlier are still waiting.
Use a PriorityQueue<Patient> where Patient implements Comparable<Patient> and compares severity, then arrival number. At the end print how many were treated, how many are still waiting, who would be next, and the total number of times somebody was overtaken.
For the input
arrive Lina 3 arrive Omar 1 arrive Mei 3 next next arrive Ana 2 next next next
the program prints
treat Omar (severity 1, arrived #2) ahead of 1 earlier patient(s)
treat Lina (severity 3, arrived #1)
treat Ana (severity 2, arrived #4) ahead of 1 earlier patient(s)
treat Mei (severity 3, arrived #3)
nobody is waiting
Treated: 4, still waiting: 0
Times somebody was overtaken: 2