2013-03-18 21 views
3

我目前正在學習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). 

我的問題是,我會在哪裏創建每個病人(分配名稱和病情嚴重程度),並可以有人幫助我(請解釋因爲我想學習,即時通訊不要求直接代碼或答案)的優先順序方面,以及如何優先到達時間相同嚴重程度的患者?

在此先感謝您的幫助或輸入每個人!

+0

「病人」類是作爲模板給予您的還是您編碼的? – 2013-03-18 03:19:47

+0

http://en.wikipedia.org/wiki/Priority_queue會爲您提供有關優先級隊列是什麼,以及如何實施它的想法。您應該在main()方法中創建患者並將其添加到ER中。 – Patashu 2013-03-18 03:23:39

+0

@TheocharisK。我編碼它......所以設計很可能是不適當或效率低下。我希望我的設計正確嗎?!?!?!隨時讓我知道我是怎麼做到的! PS:我在compareTo方法中的「那個」上出現了一個錯誤,儘管我後來要解決這個錯誤! – choloboy7 2013-03-18 03:28:39

回答

1

開始與像FrontDeskController創建特定的控制器,在該類中創建方法e.g register/checkIncheckOut。您將在此插入/刪除所有患者數據,並收集您認爲適合您的病例的單個Collection中的所有數據。

要優先隊列,如果有可能單獨的Collection要處理,所以你必須用簡單的排序算法e.g快速排序排序,排序的數據傳遞給另一個收集如參見QueueStack。我認爲這種方法很好,在ER類。

+0

所以你基本上說要做一個單獨的課程來處理到達時間和日期類信息? – choloboy7 2013-03-18 03:49:13

+1

你是什麼意思的日期類信息? 當患者到達時獲得她/他的到來時間,將其保存在患者屬性中,讓病人班級具有「Date timeArrival」。 然後在ER類中,您必須按日期或條件值對所有患者數據進行排序 – 2013-03-18 04:06:19

+0

此類是否會擴展患者? – choloboy7 2013-03-18 13:55:42