代码拉取完成,页面将自动刷新
package week3;
// 使用队列演示售票处模拟排队。
import java.util.*;
public class TicketCounter {
final static int PROCESS = 120;
final static int MAX_CASHIERS = 10;
final static int NUM_CUSTOMERS = 100;
public static void main(String[] args) {
Customer customer;
Queue<Customer> customerQueue = new LinkedList<Customer>();
int[] cashierTime = new int[MAX_CASHIERS];
int totalTime, averageTime, departs, start;
// 模拟不同数量的收银员。
for (int cashiers = 0; cashiers < MAX_CASHIERS; cashiers++)
{
// 初始化每个收银员的时间为0。
for (int count = 0; count < cashiers; count++)
{
cashierTime[count] = 0;
}
// 加载客户队列
for (int count = 1; count <= NUM_CUSTOMERS; count++)
{
customerQueue.add(new Customer(count * 15));
}
totalTime = 0;
// 处理队列中的所有客户
while (!(customerQueue.isEmpty()))
{
for (int count = 0; count <= cashiers; count++)
{
if (!(customerQueue.isEmpty()))
{
customer = customerQueue.remove();
if (customer.getArrivalTime() > cashierTime[count])
{
start = customer.getArrivalTime();
}
else
{
start = cashierTime[count];
}
departs = start + PROCESS;
customer.setDepartureTime(departs);
cashierTime[count] = departs;
totalTime += customer.totalTime();
}
}
}
// 输出模拟结果
averageTime = totalTime / NUM_CUSTOMERS;
System.out.println("Number of cashiers: " + (cashiers + 1));
System.out.println("Average time: " + averageTime + "\n");
}
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。