CS 232: Data Structures and Problem Solving

Spring 1999

Assignment 5 (1 Week Lab)

Queuing Simulations

Due Monday March 22 (20 pts)

For this assignment, you will use a Queue class for simulating the arrival and servicing of customers at a bank. A queue is known as a FIFO (first-in-first-out) list since items are added at one end (the rear) and removed from the other end (the front). Our everyday lives are full of queues, from the lines at a grocery store to jobs waiting to be printed on a network printer. As such, the queue data structure is commonly used in simulations of real-world events.

Using the Queue class provided by the text and located in the lab5 directory, write a program (saved in the file Bank.java) which simulates customers arriving and being served at a bank. In order to simplify this task, we will make some assumptions about the bank and its customers:

Your program will need to step through each minute of the day, using a random number generator to determine whether a customer has arrived and if so, the length of their transaction. And since customers may arrive while the teller is busy serving someone else, you will need to be able to store customer information in a queue so that waiting customers can be served in the correct order. You may find it useful to define the following class for storing customer information:

  class CustomerInfo {    // class for repr. a customer:
     int id;              //   stores the customer ID #,
     int arrived;         //   arrival time, and
     int length;          //   length of transaction
  } 

For the customer ID number, you can simply use the order of arrival. That is, the first customer of the day has ID # 1, the second customer has ID # 2, and so on. Your program should display the appropriate information whenever a customer arrives, is served, or departs. At the end of the simulation, your program should display the number of customers served, the average wait time (time spent waiting in the queue) over all the customers , and the maximum wait time. For example, a simulation with NUM_MINUTES = 20, ARRIVAL_PROB = 15, and MAX_TRANSACTION = 4 might produce the following output:

  2:  customer 1 arrives (transaction length = 1)
  2:   customer 1 served (busy until 3)
  3:     customer 1 departs.
  6:  customer 2 arrives (transaction length = 3)
  6:   customer 2 served (busy until 9)
  9:     customer 2 departs.
  18:  customer 3 arrives (transaction length = 2)
  18:   customer 3 served (busy until 20)
  19:  customer 4 arrives (transaction length = 3)
  20:     customer 3 departs.
  20:  customer 5 arrives (transaction length = 3)
  20:   customer 4 served (busy until 23)
  23:     customer 4 departs.
  23:   customer 5 served (busy until 26)
  26:     customer 5 departs.
 
  Customers served  = 5
  Average wait time = 0.8 minutes
  Maximum wait time = 3 minutes

Note that in this example, customer 4 arrived while customer 3 was still being served. Thus, she had to wait in the queue for 1 minute until the teller was free. Similarly, customer 5 had to wait 3 minutes until the teller was done with customer 4. Also note that the times displayed in this simulation exceed NUM_MINUTES, the number of minutes in the banking day. Your program should certainly stop allowing customers to enter the bank after NUM_MINUTES, but any customers that entered the bank before closing time should be served.

ANALYSIS: Once you have your bank simulation program working, answer the following questions (please use a word processor to write your answers):

  1. Assuming a banking day of 8 hours, how many customers would you expect to serve if the arrival probability were 20%. Do your simulations support this answer?

  2. Assuming a banking day of 8 hours, arrival probability of 15%, and a maximum transaction time of 10 minutes, what is the average wait time for customers at the bank. Run several simulations and comment on the consistency of the results.

  3. Assuming a banking day of 8 hours and a maximum transaction time of 8 minutes, what arrival probability can the bank handle and still keep the maximum wait time for customers under 10 minutes. Explain how you came up with this number.

  4. What should happen if the arrival probability is 0%? Do your simulations support this answer?

  5. What should happen if the arrival probability is 100%? Do your simulations support this answer?

Submission
Turn in hardcopies of the following: