import java.util.*; public class Market { // useful constants: public static int NUM_PARTICIPANTS = 20; public static int NUM_CHEATERS = 4; public static int NUM_IMPULSIVES = 3; public static int MAX_NUM_DEALS = 20; // this can be used anywhere it's needed in the program: public static Random gen = new Random(); // the participants live here: public static ArrayList participants = new ArrayList(); public Participant getParticipant() { int i = gen.nextInt(NUM_PARTICIPANTS); return participants.get(i); } public void runSimulation() { // create participants: for(int i = 0; i < NUM_PARTICIPANTS; i++) { Participant p = new Participant(this, i); if (i < NUM_CHEATERS) { // p is a cheater } else if (i < NUM_CHEATERS + NUM_IMPULSIVES) { // p is impulsive } else { // p is honest } participants.add(p); } // start participants: for(int i = 0; i < NUM_PARTICIPANTS; i++) { participants.get(i).start(); } // wait for participants to die: for(int i = 0; i < NUM_PARTICIPANTS; i++) { try { participants.get(i).join(); } catch(InterruptedException ie) { System.err.println(ie.getMessage()); } finally { System.out.println("" + participants.get(i) + " has died"); } } // display resullts: for(int i = 0; i < NUM_PARTICIPANTS; i++) { System.out.println(participants.get(i)); } // I die! System.out.println("The master will now die ... "); } public static void main(String[] args) { Market wallStreet = new Market(); wallStreet.runSimulation(); } }