以下是对场地类的一些更改。
class Venue {
PriorityQueue<Event> pq = new PriorityQueue<Event>(Comparator.comparing(Event::getTime));
public static void main(String[] args) {
Venue v = new Venue();
v.addEvents();
v.display(v.pq);
}
private void addEvents() {
pq.add(new Event("stand up", 90, 200));
pq.add(new Event("rock concert", 120, 150));
pq.add(new Event("theatre play", 60, 120));
pq.add(new Event("street performance", 70, 80));
pq.add(new Event("movie", 100, 55));
}
private void display(PriorityQueue<Event> e) {
while (!e.isEmpty()) {
System.out.println(e.remove());
}
}
}
队列位于班级级别,因此每个场馆都可以有自己的队列。main方法只调用其他方法,但理想情况下应该放在不同的类中。该显示将在场馆实例上调用,您可以使用该方法进行统计,同时从队列中删除每个项目。