CS151 Lab 4:  Event-Driven Simulations

Home Search E-mail Java Resources Discussion
Event Queues
Bank Simulation
Tricks and Traps

In this lab we will get (lots!) of practice using stacks and queues by attempting to model the behavior of the ATM and teller lines at a bank.   In doing so, we will also see how to construct an event-driven simulation model.  

It will take two weeks to get the full bank simulation running.   Do not even think of trying to write all the code at once!  

The key to success here is to maintain the discipline to write and thoroughly test small pieces of code at at time.

The purpose of this lab is to get you to wrestle with stacks and queues. You should be careful not to take advantage of structures that come with additional functionality.  Note that while the Java libraries include Stack and Vector classes, you are not bound to use them.  You are free to construct your own stacks and/or queues from Java's libraries. You may want to use LRStruct or something else for some of the lists.   Do note the following:.

  • Sun does not supply a queue class.  However, Vector has all the methods needed for a queue.   Sun does supply a Stack object (subclassed from Vector) which has a push() and a pop() method.   enqueue(x) is the same as insertElementAt(x, 0). 
  • No matter which stack, queue or vector implementation you use, consider subclassing them to add the additional intrinisic functionality you need.    An object should be able to take care of itself.
  • We've been using LRStruct quite a bit. An advantage is that its use will eliminate all the isEmpty() checks that Sun's classes will make you do. There are places in this assignment where it might be appropriate to use an LRStruct -- but don't use it where a stack or a queue is called for.

The lab as it is shown here is two weeks worth of material.  You should have the following working by the end of the first week:

  • Constructed Event Queues
  • The ability to fill event queues with Events
  • A functional EventManager which correctly processes events.
  • Have everything in the "Event Queues" subsection working.
  • Design the structure of queues you want to have and how you want to handle incoming customer job data.
  • Have customers arrive and place their job data into the correct event queues  (Don't worry about how to randomize the customer job data, such as whether a job is "ATMable": we strongly suggest you hard-code these data for now, as non-random data make debugging the system a lot easier.  Once the system is stable and you know that it works, then we'll worry about randomizing the data.)
  • When designing the structure for the queues, keep in mind the "processInterval" method referred to in the "Queues of Queues" subsection in the "Bank Simulation" subsection.  You do not have to write the processInterval method this week, but you should keep in mind having to write it when you are designing your event queue asrchitecture.
  • Write up the text file mentioned at the end of the "Queues of Queues" subsection.  Lay out in detail your architecture and the relationships between the different types of events.

The rest of the simulation should be constructed and put in place the second week.  This includes:

  • Pulling events off of the event queues and handling them properly
  • Using the Spinner class to randomize customer job data effectively
  • Gathering data on customer job times

 

Let's get going with the subsections to the left!