void setup(){
Patient[] P = {new Patient("Aruk Pupatee",80,false),new Patient("Tanaphat Kalaya",100,true),
new Patient("Anuparp Chewakumnuan",20,true),new Patient("Apichit Saisuttivong",100,false)};
PatientQueue PQ = new PatientQueue(P);
PQ.showAllPatient();
Patient P1 = new Patient("Anothai Arunthong",90,false);
Patient P2 = new Patient("Warunatid Thongsalee",100,false);
Patient P3 = new Patient("Chayanin Khawsanit",60,true);
PQ.addPatient(P1);
PQ.addPatient(P2);
PQ.addPatient(P3);
PQ.showAllPatient();
PQ.removePatient();
PQ.showAllPatient();
}
class PatientQueue{
Patient[] HospitalPatient;
PatientQueue(Patient p){
this.HospitalPatient = new Patient[1];
this.HospitalPatient[0] = p;
}
PatientQueue(Patient[] p){
this.HospitalPatient = p;
this.sortQueue();
}
void sortQueue(){
Patient[] p = new Patient[this.HospitalPatient.length-this.getTotalEmer()];
int pcount = 0;
for(int i=0;i<this.HospitalPatient.length;i++){
if(!this.HospitalPatient[i].getEmer()){
p[pcount] = this.HospitalPatient[i];
pcount++;
}
}
for(int i=0;i<this.HospitalPatient.length;i++){
for(int j=i;j<this.HospitalPatient.length;j++){
if(!this.HospitalPatient[i].getEmer() && this.HospitalPatient[j].getEmer()){
Patient temp = this.HospitalPatient[i];
this.HospitalPatient[i] = this.HospitalPatient[j];
this.HospitalPatient[j] = temp;
}
else {
if(this.HospitalPatient[i].getEmer() && this.HospitalPatient[j].getEmer()){
if(this.HospitalPatient[i].getBlood() > this.HospitalPatient[j].getBlood()){
Patient temp = this.HospitalPatient[i];
this.HospitalPatient[i] = this.HospitalPatient[j];
this.HospitalPatient[j] = temp;
}
}
}
}
}
for(int i=(this.HospitalPatient.length-1);i>(this.getTotalEmer()-1);i--){
HospitalPatient[i] = p[pcount-1];
pcount--;
}
}
void addPatient(Patient p){
Patient[] temp = new Patient[this.HospitalPatient.length+1];
for(int i=0;i<this.HospitalPatient.length;i++){
temp[i] = this.HospitalPatient[i];
}
temp[temp.length-1] = p;
this.HospitalPatient = temp;
this.sortQueue();
}
void removePatient(){
Patient[] temp = new Patient[this.HospitalPatient.length-1];
for(int i=0;i<(this.HospitalPatient.length-1);i++){
temp[i] = this.HospitalPatient[i+1];
}
this.HospitalPatient = temp;
}
void showAllPatient(){
for(int i=0;i<this.HospitalPatient.length;i++){
print((i+1)+")."+this.HospitalPatient[i].getName());
print(" Blood : "+this.HospitalPatient[i].getBlood()+"%");
if(this.HospitalPatient[i].getEmer()){
println(" <<< EMERGENCY !!");
}
else println("");
}
println("----------------------------------------------------");
}
int getTotalEmer(){
int count=0;
for(int i=0;i<this.HospitalPatient.length;i++){
if(this.HospitalPatient[i].getEmer()){
count++;
}
}
return count;
}
}
class Patient{
String name;
int blood;
boolean isEmergency;
Patient(String n,int b,boolean e){
this.name = n;
if(b>100){
this.blood = 100;
}
else this.blood = b;
this.isEmergency = e;
}
String getName(){
return this.name;
}
int getBlood(){
return this.blood;
}
boolean getEmer(){
return this.isEmergency;
}
}