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

📄 waitingroom.java

📁 Java经典例程 从外国一大学计算机教授出版物下载的代码 经典
💻 JAVA
字号:
import myutilities.*;

class WaitingRoom {
  /*  Simulation the Waiting Room   by J M Bishop    Jan 1997
   *  ---------------------------   Java 1.1
   *  Shows a queue growing and shrinking in response to
   *  random events.
   *
   * Illustrates queues and home-made queue iterators.
   */

  public static void main (String args []) throws QueueException {
      new WaitingRoom ();
  }

  WaitingRoom () throws QueueException {
    Queue chairs = new Queue (7);
    int patient;
    int choice;

    System.out.println("*** Doctor's Waitintg Room Simulation ***");
    System.out.println("There are 7 chairs");
    System.out.println("Arrivals on 2,4,6; patients seen on 1,2");
    System.out.println();
    System.out.println("Time\tChoice\tPatient numbers");

    for (int i = 2; i<30; i++) {
      choice = (int) (Math.random()*6+1);
      System.out.print(i+"\t"+choice+"\t");
      display(chairs);
      try {
        if (choice == 1 || choice == 2)
          if (!chairs.empty())
            patient = ((Integer) chairs.remove()).intValue();
        if (choice == 2 || choice == 4 || choice == 6)
          chairs.add(new Integer(i));
      }
      catch (QueueException e) {
        System.out.println("\t\t\tWaiting room "+e.getMessage());
      }
    }
  }

  void display (Queue q) {
    if (q.empty()) System.out.print("Empty"); else
    for (q.reset(); !q.eol(); q.succ())
      System.out.print(((Integer) q.current()).intValue() +"  ");
    System.out.println();
  }
}

⌨️ 快捷键说明

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