import lift.LiftMonitor;
import lift.LiftThread;
import lift.LiftView;
import lift.PassengerThread;

public class LiftMain {
  public static void main(String[] args) {
    // Could be read from args
    final int NBR_FLOORS = 12, MAX_PASSENGERS = 4;

    LiftView view = new LiftView(NBR_FLOORS, MAX_PASSENGERS);

    // LiftMonitor passed to all threads
    LiftMonitor monitor = new LiftMonitor(view, NBR_FLOORS);

    // Static array since the number of passengers is fixed
    PassengerThread[] pass_threads = new PassengerThread[20];

    for (PassengerThread p : pass_threads) {
      p = new PassengerThread(view, monitor);
      p.start();
    }

    LiftThread lift = new LiftThread(view, monitor);
    lift.start();

    // Rejoin all threads, in practice this is redundant
    try {
      // Passenger threads first
      for (PassengerThread p : pass_threads) {
        p.join();
      }
      lift.join();
    } catch (InterruptedException e) {
      e.printStackTrace();
    }
  }
}
