SimulatorMain.java Simulator.java
Study the file Simulator.java for a few minutes. I'll wait.
Now build and run the project. Enter 3 for the mean arrival time and 22 for the maximum arrival time. Recall that the service time for each car is 10 minutes. The output has the following sequence of arrival times:
4 5 8 13 16 19 20 22 25 -- not counted: after the maximum arrival time
We can calculate the average waiting time, by hand, as follows. The arrival at time 4 immediately enters the wash station, so its waiting time is 0 minutes. The arrivals at times 5, 8 and 13 are enqueued. At time 14, the arrival at time 4 leaves the wash station and departs from the car wash. Then the arrival at time 5 is dequeued and enters the wash station. Its waiting time is 9 minutes. In general, waiting time = current time - arrival time. So in this case we get waiting time = 14 - 5 = 9 minutes.
The arrivals at times 16, 19 and 20 are enqueued, but the arrival at time 22 is turned away as an overflow. At time 24, the arrival at time 5 leaves the car wash, and the arrival at time 8 is dequeued and enters the wash station. Its waiting time = 24 - 8 = 16 minutes. At time 34, the arrival at time 8 leaves the car wash, and the arrival at time 13 is dequeued and enters the wash station.
The following chart summarizes the events:
Time Event Waiting Time ---- ----------------- ------------ 4 Arrival 5 Arrival 8 Arrival 13 Arrival 14 Departure 0 16 Arrival 19 Arrival 20 Arrival 22 Arrival - Overflow 24 Departure 9 34 Departure 16 44 Departure 21 54 Departure 28 64 Departure 35 74 Departure 44
The sum of the waiting times is 153, and there are 7 cars (the overflow does not count). So the average waiting time is 153 / 7 = 21.9 minutes, rounded to one decimal place.