// Project: Observer // Module: casino // Source code file: Main2.java. // The Manager object is the observer. // The SlotMachine objects are the observables. import java.io.IOException; import java.util.ArrayList; public class Main2 { public static void main(String[] args) throws IOException, InterruptedException { Manager casinoManager = new Manager("jackpot-log.txt"); // Create array list for machines. ArrayList machines = new ArrayList( ); // Create SlotMachine objects. for(int i = 1; i <= 100; i++) { SlotMachine machine = new SlotMachine(1000 + i); machines.add(machine); machine.addObserver(casinoManager); } // Repeatedly play each machine 20 times. for(int k = 0; k <= 20; k++) { for(int j = 0; j <= 20; j++) { for(SlotMachine machine: machines) { machine.play( ); } } // Sleep for 2000 milliseconds. Thread.sleep(2000); } System.out.println(20 * 20 * machines.size( ) + " plays completed."); } }