Java Reference
In-Depth Information
This means the first customer spends five minutes at the teller, the second spends eight minutes, the third spends
seven minutes, and so on.
Table 6-1 shows what happens to these ten customers.
Table 6-1. Tracking Ten Customers
Customer
Arrives
Start
Service
Counter
Service
Time
Departs
Wait
Time
1
9:03
9:03
C1
5
9:08
0
2
9:04
9:04
C2
8
9:12
0
3
9:06
9:08
C1
7
9:15
2
4
9:10
9:12
C2
6
9:18
2
5
9:12
9:15
C1
9
9:24
3
6
9:17
9:18
C2
4
9:22
1
7
9:18
9:22
C2
7
9:29
4
8
9:21
9:24
C1
4
9:28
3
9
9:23
9:28
C1
9
9:37
5
10
9:27
9:29
C2
6
9:35
2
The first customer arrives at 9:03 and goes straight to C1. His service time is five minutes,
so he will leave C1 at 9:08.
The second customer arrives at 9:04 and goes straight to C2. His service time is 8 minutes,
so he will leave C2 at 9:12.
The third customer arrives at 9:06. At this time, both C1 and C2 are busy, so he must wait.
C1 will be the first to become free at 9:08. This customer will begin service at 9:08. His service
time is seven minutes, so he will leave C1 at 9:15. This customer had to wait in the queue for
two minutes.
The fourth customer arrives at 9:10. At this time, both C1 and C2 are busy, so he must wait.
C2 will be the first to become free at 9:12. This customer will begin service at 9:12. His service
time is six minutes, so he will leave C2 at 9:18. This customer had to wait in the queue for
two minutes.
And so on. Work through the rest of the table to make sure you understand how those values are obtained.
Also observe that once the tellers started serving, they had no idle time. As soon as one customer left, another
was waiting to be served.
6.9.1 Programming the Simulation
We now show how to write a program to produce Table 6-1 . First we observe that it is no more difficult to write the
program for several counters than it is for two. Hence, we will assume that there are n ( n < 10 ) counters. For this
particular example, we will set n to 2.
We will use an array depart[10] such that depart[c] will hold the time at which counter c will next become free.
We will not use depart[0] . If we need to handle more than nine counters, we just need to increase the size of depart .
 
 
Search WWH ::




Custom Search