class Counter extends Thread {

  Counter (Museum m, int q) {
    museum = m;
    queue = q;
  }

  public void run () {

    // Decide how many Walkmen are needed for a
    // group of visitors and attempt to hire them
    // (waiting until successful). The visitors are
    // sent off on their own to walk around (by
    // starting a new Visitors thread which runs
    // independently.)
    while (true) {
      int w = a(7);
      museum.hire(queue, w);
      new Visitors (museum, w).start();

      // Wait a bit before the next people arrive
      try {sleep(a(100));}  catch(InterruptedException e) {}
    }
  }

  Museum museum;
  int queue;

  static int a (int x) {
    return (int) (Math.random() * x) +1;
  }

}
