【发布时间】:2013-03-06 08:11:57
【问题描述】:
我目前在学校学习 ADT,为了完成一项任务,我必须在医院模拟急诊室。我目前有我的病人类如下:
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).
我的问题是,我将在哪里创建每个患者(指定姓名和病情严重程度)并且有人可以帮助我(请解释因为我想学习,我不要求直接代码或答案)优先方面以及如何按到达时间优先考虑相同严重程度的患者?
提前感谢大家的帮助或输入!
【问题讨论】:
-
patient类是作为模板提供给您的还是您编写的? -
en.wikipedia.org/wiki/Priority_queue 将为您提供有关优先级队列是什么、作用以及如何实现它的想法。您应该在 main() 方法中创建患者并将其添加到您的 ER。
-
@TheocharisK。我对其进行了编码......所以设计很可能不合适或效率低下。我希望我设计正确?!?!?!随时让我知道我是怎么做的! PS:我的 compareTo 方法中的“那个”确实有一个错误,尽管我稍后会解决这个错误!
-
您在
that关键字上出现错误,因为Java 中根本没有这样的关键字。您应该将其替换为other。还有一个很好的提示是将Date变量添加到您的Patient类中,您可以在其中保存每位患者的到达时间,以便以后进行比较。 -
感谢您的帮助@TheocharisK。
标签: java oop queue priority-queue