代码拉取完成,页面将自动刷新
package wek3;
import java.util.*;
/**
* TicketCounter demonstrates the use of a queue for simulating a line of customers.
*
* @author Lewis and Chase
* @version 4.0
*/
public class TicketCounter
{
private final static int PROCESS = 120;
private final static int MAX_CASHIERS = 10;
private 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;
// run the simulation for various number of cashiers
for (int cashiers = 0; cashiers < MAX_CASHIERS; cashiers++)
{
// set each cashiers time to zero initially
for (int count = 0; count < cashiers; count++) {
cashierTime[count] = 0;
}
// load customer queue
for (int count = 1; count <= NUM_CUSTOMERS; count++) {
customerQueue.add(new Customer(count * 15));
}
totalTime = 0;
// process all customers in the queue
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();
}
}
}
// output results for this simulation
averageTime = totalTime / NUM_CUSTOMERS;
System.out.println("Number of cashiers: " + (cashiers + 1));
System.out.println("Average time: " + averageTime + "\n");
}
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。