Java Reference
In-Depth Information
The class WaitLine simulates the waiting line for a given period of time. During this time, cus-
tomers enter the line at random intervals and leave it after being served. At the conclusion of the
simulation, the class computes the summary statistics. Figure 10-4 shows a CRC card for this class.
The class Customer records and makes available the customer's arrival time, transaction time,
and customer number. Figure 10-5 contains a class diagram for WaitLine and Customer .
FIGURE 10-4
A CRC card for the class WaitLine
WaitLine
Responsibilities
Simulate customers entering and leaving a
waiting line
Display number served, total wait time,
average wait time, and number left in line
Collaborations
Customer
FIGURE 10-5
A diagram of the classes WaitLine and Customer
WaitLine
1
line —a queue of customers
numberOfArrivals —number of customers
numberServed —number of customers actually served
totalTimeWaited— total time customers have waited
simulate(duration, arrivalProbability, maxTransactionTime)
displayResults()
Customer
*
arrivalTime
transactionTime
customerNumber
getArrivalTime()
getTransactionTime()
getCustomerNumber()
10.7
The method simulate . The method simulate is the heart of this example and of the class WaitLine .
To maintain the clock for this time-driven simulation, simulate contains a loop that counts up to a
given duration. For example, the clock could simulate one hour by counting minutes, beginning at 0
and continuing until 60.
 
Search WWH ::




Custom Search