我目前正在學習ADT的學校和作業,我必須在醫院模擬ER。目前,我有我的病人類,如下所示:在Java中模擬醫院(優先級隊列)
public class Patient implements Comparable<Patient>{
private String name;
private int condition;
public Patient(String n, int c){
this.name = name;
this.condition = condition;
}
public String toString(){
return name;
}
public int boundary(int condition) {
if (condition > 17){
return 17;
}
else if (condition < 1) {
return 1;
}
return condition;
}
public int compareTo(Patient other) {
if(this.condition < that.condition) {
return -1;
}
else if(this.condition > that.condition) {
return +1;
}
else {
return this.name.compareTo(that.name);
}
}
}
,我需要現在做一個類被稱爲ER()...有很多方法,我要實現具備的條件如下:
public void addPatient(String name, int severity, Date time)
// Purpose: adds a person to the waiting list in the emergency
// room.
// Preconditions: name is not null
// severity is an integer in the range [1,17]
// time is the current time
// Postconditions: the person is added to the emergency room
// waiting list. The "priority" in the list is
// based on severity (1 being least important and
// 17 being most important) first and for patients
// with equal severity, based on time (FIFO).
我的問題是,我會在哪裏創建每個病人(分配名稱和病情嚴重程度),並可以有人幫助我(請解釋因爲我想學習,即時通訊不要求直接代碼或答案)的優先順序方面,以及如何優先到達時間相同嚴重程度的患者?
在此先感謝您的幫助或輸入每個人!
「病人」類是作爲模板給予您的還是您編碼的? – 2013-03-18 03:19:47
http://en.wikipedia.org/wiki/Priority_queue會爲您提供有關優先級隊列是什麼,以及如何實施它的想法。您應該在main()方法中創建患者並將其添加到ER中。 – Patashu 2013-03-18 03:23:39
@TheocharisK。我編碼它......所以設計很可能是不適當或效率低下。我希望我的設計正確嗎?!?!?!隨時讓我知道我是怎麼做到的! PS:我在compareTo方法中的「那個」上出現了一個錯誤,儘管我後來要解決這個錯誤! – choloboy7 2013-03-18 03:28:39