Bankteller控制台应用程序
我正在制作一个简单的应用程序来模拟银行家的问题 。 我想要模拟的是:
你在商店里有4个柜台。 1柜台开放。 客户开始进入并进入第一个柜台的生产线。
当第四个客户进入第一个柜台的生产线时,应打开另一个柜台。 该线应在两个计数器之间平均分配。当第二个柜台的客户得到帮助而没有新客户进入该线时,计数器应该关闭。 基本上4太多了。
我似乎无法弄明白。 我知道我需要使用队列。 但是怎么样? 有人能在控制台应用程序中给我一个例子吗? 优先C#。
提前致谢。
这是我到目前为止尝试过的,
注册类:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace RegisterCounter { class Register { private int customerCount; public Queue Line = new Queue(); public Register() { customerCount = 2; } public Register(int customerCount) { this.customerCount = customerCount; } public int getCustomers() { return customerCount; } }
}
客户类:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace RegisterCounter { class Customer { private int checkoutTime; public Customer() { checkoutTime = 3; } public Customer(int checkoutTime) { this.checkoutTime = checkoutTime; } public int GetCheckoutTime() { return checkoutTime; } }
}
注册经理:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace RegisterCounter { class RegisterManager { public List registers = new List(); Register r1 = new Register(); Customer c1 = new Customer(); public RegisterManager() { registers.Add(r1); } public void ManageCustomers() { for (int i = 0; i < registers.Count; i++) { registers.Insert(i, new Register()); if (i / 4 <= registers..Line.Count) { } } } }
}