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.
A very simple person class is provided for you.
Skeleton code: Person.java
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:
- public void enqueue(Object o)
- public Object dequeue()
- public Object peek()
- public int size()
Skeleton code: none! You need to write this from the ground up.
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: Generator.java
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.
- public DMV(int startTime, int endTime) - This should intiailize all your instance variables
- public void startClass() - This method should dequeue everyone from the class line
- public void moveMainLine()- This method should move people from the front of the main line into the next to lines. The maximum number of people that should be allowed to go in the class and license line is 10 (10 for each).
- public void getLicense() - This method should dequeue one person from the license line
- public String retStats() - This should take all the information you collected during run and calculate the average wait time for getting a license, taking a class, as well as the total number of people processed and people left waiting outside.
Skeleton code: DMV.java
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.