Java Reference
In-Depth Information
transactionTimeLeft--;
else if (!line.isEmpty())
{
Customer nextCustomer = line.dequeue();
transactionTimeLeft = nextCustomer.getTransactionTime() - 1;
int timeWaited = clock - nextCustomer.getArrivalTime();
totalTimeWaited = totalTimeWaited + timeWaited;
numberServed++;
System.out.println("Customer "
+ nextCustomer.getCustomerNumber()
+ " begins service at time " + clock
+ ". Time waited is " + timeWaited);
} // end if
} // end for
} // end simulate
/** Displays summary results of the simulation. */
public void displayResults()
{
System.out.println();
System.out.println("Number served = " + numberServed);
System.out.println("Total time waited = " + totalTimeWaited);
double averageTimeWaited = (( double )totalTimeWaited) /
numberServed;
System.out.println("Average time waited = " + averageTimeWaited);
int leftInLine = numberOfArrivals - numberServed;
System.out.println("Number left in line = " + leftInLine);
} // end displayResults
/** Initializes the simulation. */
public final void reset()
{
line.clear();
numberOfArrivals = 0;
numberServed = 0;
totalTimeWaited = 0;
} // end reset
} // end WaitLine
10.9
Sample output. The Java statements
WaitLine customerLine = new WaitLine();
customerLine.simulate(20, 0.5, 5);
customerLine.displayResults();
simulate the line for 20 minutes with a 50 percent arrival probability and a 5-minute maximum trans-
action time. They produce the following results:
Customer 1 enters line at time 0. Transaction time is 4
Customer 1 begins service at time 0. Time waited is 0
Customer 2 enters line at time 2. Transaction time is 2
Search WWH ::




Custom Search