Java Reference
In-Depth Information
1 /**
2 * Run the simulation until stoppingTime occurs.
3 * Print output as in Figure 13.4.
4 */
5 public void runSim( long stoppingTime )
6 {
7 Event e = null;
8 int howLong;
9
10 while( !eventSet.isEmpty( ) )
11 {
12 e = eventSet.remove( );
13
14 if( e.time > stoppingTime )
15 break;
16
17 if( e.what == Event.HANG_UP ) // HANG_UP
18 {
19 availableOperators++;
20 System.out.println( "User " + e.who +
21
" hangs up at time " + e.time );
22 }
23 else // DIAL_IN
24 {
25 System.out.print( "User " + e.who +
26 " dials in at time " + e.time + " " );
27 if( availableOperators > 0 )
28 {
29 availableOperators--;
30 howLong = r.nextPoisson( avgCallLen );
31 System.out.println( "and connects for "
32 + howLong + " minutes" );
33 e.time += howLong;
34 e.what = Event.HANG_UP;
35 eventSet.add( e );
36 }
37 else
38 System.out.println( "but gets busy signal" );
39
40 nextCall( freqOfCalls );
41 }
42 }
43 }
figure 13.9
The basic simulation routine
Search WWH ::




Custom Search