1 Star 0 Fork 0

CS-IMIS-23/20172306

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
TicketCounter.java 2.40 KB
一键复制 编辑 原始数据 按行查看 历史
20172306 提交于 7年前 . 书上代码
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");
}
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Java
1
https://gitee.com/CS-IMIS-23/20172306.git
git@gitee.com:CS-IMIS-23/20172306.git
CS-IMIS-23
20172306
20172306
master

搜索帮助