Lab 5 - DMV
Due: Wednesday, February 28, 2007 at 11:59 pm


This lab will simulate the DMV. People arrive every now and then and wait in line outside. When the DMV opens, the people in the front of the line can move inside if there is room for them in the line they want. If there isn't room inside, then they sit at the front of the line blocking everone else. This should seem rather inefficient: Imagine that there are the maximum number of people in line for a class and the first person in the main line wants to take a class. Even if everyone after the first person wants to get their license, they have to wait until the person who wants to take the class is dequeued.

Java classes

Person class

A very simple person class is provided for you.

Skeleton code:

Queue class

You will need to implement a LinkedList based Queue class to model the lines. This class should accept Objects and not Person's (you can cast the Object back into a Person). You shouldn't just cut and paste your linkedlist code from the previous labs, you should be able do this with a specific remove and a specific add case. Your Queue class must contain the following methods in addition to the constructor:

Skeleton code: none! You need to write this from the ground up.

Generator class

This class will create Person's to insert into the simulation. They will be randomly generated and will either be there to get a license or to take a driving class. The Generator that we provide has a 1 in 4 chance of adding a person .

Source code:

DMV class

This class performs the simulation. It has several instance variables, the most important being the three Queues. The run function actually performs the simulation, going from openingTime to finishingTime; it steps through time adding people, moving people from the outside line inside, and dequeueing the class and licenses queues appropriately. There are five methods you'll have to implement. Remember to update all the instance variables appropriately in each of them.

Skeleton code:

Main Driver class

This driver should simply create a few different DMV's with different starting and end times, run them, and print the results. Use this for general testing along the way if you want.

Skeleton: None! You should be able to do this part pretty easily.

Plan of attack

  1. Write a Queue class containing the methods noted above.
  2. TEST, TEST, TEST your queue!
  3. Complete the DMV class by writing the required methods
  4. TEST, TEST, TEST the entire project.