package UE21_290425_Bruecke;

public class Generator extends Thread {
    private static final Guard guard = new Guard();
    private static final Generator generator = new Generator();
    private static long carIndex = 0;

    public static void main(String[] args) {
        System.out.println("Statistics:");
        generator.start();
        guard.start();
    }

    @Override
    public void run() {
        while (guard.waitingCars.size() <= Variables.MAX_WAITING_CARS) {
            try {
                Thread.sleep((int) (Math.random() * Variables.MAX_CAR_INTERVAL + 1) * 1000L);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            Car car = new Car(guard, carIndex++);
            guard.arriving(car);
        }
        
    }
}
