⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 supermarket.java

📁 Java程序设计技巧与开发实例附书源代码。
💻 JAVA
字号:

import java.awt.*;
import java.awt.event.*;

public class Supermarket
    extends Business
{
  private Queue[] queue = new Queue[Simulator.NUM_AGENTS];

  public Supermarket()
  {
    super("超市");
    for (int i = 0; i < queue.length; i++)
    {
      queue[i] = new Queue();
    }
  }

  public void updateDisplay()
  {
    labelServed.setText("已服务的顾客数:" + numCustomer);
    if (numCustomer != 0)
    {
      labelWait.setText("平均等待:" + (totalWait / numCustomer));
    }
    int totalSize = 0;
    for (int i = 0; i < numAgents; i++)
    {
      totalSize += queue[i].getSize();
      String s = "Agent " + i + ":已服务" + agent[i].getHandled();
      labelAgent[i].setText(s + " [" + queue[i].getSize() + "等待中]");
    }
    for (int i = numAgents; i < Simulator.NUM_AGENTS; i++)
    {
      labelAgent[i].setText("Agent " + i + ":没有激活");
    }
    labelQueue.setText("正在等待的顾客数:" + totalSize);
  }

  public void generateCustomer()
  {
    int index = 0;
    for (int i = 0; i < numAgents; i++)
    {
      if (queue[i].getSize() < queue[index].getSize())
      {
        index = i;
      }
    }
    queue[index].insert(new Customer());
  }

  public Customer requestCustomerFor(int ID)
  {
    // the queue is guarantied to release a new customer
    return queue[ID].requestCustomer();
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -