CMPS 144 Spring 2026
Prog. Assg. #3: Discrete Event Simulation
Due : 11:59pm, April 1

Background

This assignment explores a classic example of discrete event simulation, which is a category of computer application in which queues are found to be useful. The scenario to be simulated here is one in which there is a stream of customers who arrive, each seeking some kind of service. Each customer waits in a queue (!) until a clerk (i.e., a person capable of providing service) is available, after which the customer receives service and then leaves.

To simulate a stream of arriving customers, we use an instance of the class CustomerGenerator to create them. When a customer is created, it is assigned an arrival time and a service duration. In each case, these values are generated pseudo-randomly in accord with a uniform distribution over a fixed range (going from a specified minimum to a specified maximum). (These minima and maxima are given by the values of the parameters that are passed to the CustomerGenerator constructor.)

For example, in our simulation we could make it so that each "inter-arrival time" (the time between when one customer arrives and then the next) is in the range [0..10] units of time, with each (integer) value in that range being equally likely.

Such simulations can be useful in making decisions about how many clerks ought to be available for customers during certain periods of the day, based upon the frequency with which customers tend to arrive and how long it typically takes to provide service to them. Obviously, the greater the number of clerks, the less time customers will spend waiting in the queue, which will tend to make customers happy. On the other hand, the greater the number of clerks, the greater the amount of their wages, which will tend to displease the business owner. So there is a tradeoff!

The Simulation class (and specifically its simulate() method) is where the simulation actually gets carried out. Four of the methods in that class are left to the student to complete. Extensive comments within the class are there to aid the student in figuring things out! In particular, each of the stubbed methods is responsible for updating the values of one or more instance variables. It is imperative that those updates preserve the truth of all the class invariants1

Java Artifacts

This assignment involves the following Java classes, one of which needs to be completed by the student:

Java's List class

The Simulation class includes two instance variables of the data type arising from the Java interface List, both of which represent lists of Customer objects. As you would expect, a list is simply a sequence of elements. Java's concept of a list is what could be called an indexed list, meaning a sequence whose elements can be referred to by their ordinal positions (e.g., 0th, 1st, 2nd, etc.). Also, you can remove an element at a specified position and insert a new element at a specified position.

The following examples of method calls (in which it is assumed that list is bound to an object of a class (such as LinkedList) that implements the List interface) gives you all the information you need about Java lists for the purposes of this assignment.


Footnote

[1] A class invariant is a condition involving an object's instance variables that, by design, is intended to be true immediately before and immediately after a call to any of the object's methods.