gpt4 book ai didi

java - Java模拟医院(优先队列)

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:09:42 26 4
gpt4 key购买 nike

我目前在学校学习 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).

我的问题是,我究竟应该在哪里创建每个患者(指定姓名和病情严重程度),有人可以帮助我(请解释一下,因为我想学习,我不要求直接代码或答案)优先级方面以及如何按到达时间优先考虑具有相同严重程度的患者?

在此先感谢大家的帮助或意见!

最佳答案

开始创建特定的 Controller ,如 FrontDeskController,并在此类中创建方法,例如 register/checkIncheckOut。您将在此处插入/删除所有患者数据,并将所有数据收集到您认为适合您的情况的单个 Collection 中。

要对队列进行优先级排序,如果可以将要处理的 Collection 分开,那么您必须使用简单的排序算法进行排序,例如快速排序,并将排序数据传递给另一个集合 e.q Queue堆栈。我认为这种方法很适合放在 ER 类中。

关于java - Java模拟医院(优先队列),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15469237/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com