import java.util.Random; /* An instance of this class is for the purpose of generating instances ** of the Customer class. ** Note: This class is essentially the same as that found in ** "Object-Oriented Data Structers using Java", by Dale, Joyce, and Weems, ** (4th edition, Pearson) */ public class CustomerGenerator { // instance variables // ------------------ protected int minIAT; // minimum interarrival time protected int maxIAT; // maximum interarrival time protected int minST; // minimum service time protected int maxST; // maximum service time private Random rand; protected int mostRecentTime; protected int mostRecentID; public CustomerGenerator(int randSeed, int minIAT, int maxIAT, int minST, int maxST) { rand = new Random(randSeed); this.minIAT = minIAT; this.maxIAT = maxIAT; this.minST = minST; this.maxST = maxST; reset(); } // mutator // ------- public void reset() { mostRecentTime = 0; mostRecentID = -1; } // method of interest // ------------------ public Customer nextCustomer() { int interArrivalTime = minIAT + rand.nextInt(maxIAT - minIAT + 1); int serviceTime = minST + rand.nextInt(maxST - minST + 1); mostRecentTime = mostRecentTime + interArrivalTime; mostRecentID++; return new Customer(mostRecentID, mostRecentTime, serviceTime); } }