我有一个名为队列的 ArrayList,当顾客到达结账时,我将其存储在超市中。当他们付款后,我删除了 Arraylist 的第一个元素(队列中第一个的客户),但我不知道如何告诉第二个元素,现在是第一个,继续付款。此外,该客户应该正在等待“事件”。
总而言之,我正在寻找类似“信号”和“等待”的东西。
这是我所拥有的概要:
public class Customer{
public void checkItems(){
//Here goes the code for waiting his turn
//Here goes the code for paying items (already done)
//The next line is how I remove the client of the queue
Globals.checkoutList.get(currentCheckout).queue.remove(0);
Checkout.nextCustomer();
}
}
public class Checkout{
public static void nextCustomer(){
//Here I should tell the next customer that it is his turn
}
}
问候和感谢。
编辑:也许使用异常?也将不胜感激。
最佳答案
Customer
不应将自己从队列中移除,这是 Checkout
或 Checkout
的控制实体的工作。此外,当您删除列表中的第一个客户时,所有其他客户都会自动“向上移动”,您将永远只需要处理结帐队列中的第一个元素。
关于java - 一种表示某事已发生的方式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23726144/