← back to the schedule


PROJECT #2 CAR WASH SIMULATION
By Autumn C. Spaulding with Alyce Brady Edited by Sandino Vargas-Pérez




PROBLEM DESCRIPTION

The current car wash machine at Squeaky Clean Car Wash requires exactly 4 minutes to complete the regular car wash (including rinse, wax, and dry). The owners are considering upgrading their equipment, though, because they are suspicious that the average wait time for the cars is long enough that they are losing business. They are considering replacing the current machine with one that would take only 3 minutes. The upgrade will be expensive, so they would like to know in advance how much difference it will make.

Construct a simulation of the car wash to determine what the average waiting time would be during a typical day (9 am to 7 pm) using the new equipment. A car arrives at the car wash approximately every four minutes (cars don't arrive exactly four minutes apart: that would be easy to program!). Since the arrival times are uneven, there is often a waiting line. This can be simulated using a queue.

Think about how you might go about simulating this problem. How could you simulate the arrivals, waiting, and washing of the cars at the car wash?

Perhaps it would be useful to think of what can happen in a given minute in the car wash (we'll assume that at most one car can arrive in any given minute, although this is not necessary). In a car wash, you can have cars arriving, cars waiting, and cars being washed. You also have cars changing from one state to another. If a car arrives and there is a car being washed, the arriving car becomes a waiting car. If there is at least one car waiting and the car wash bay becomes available, a waiting car becomes a car being washed.

Some of the questions that are still open are: How will you determine whether a car should arrive in the current minute? (In any given minute, there is a 1 in 4 chance that a car will arrive.) How will you decide whether a car is currently being washed? How will you decide when the machine is empty? How will you represent the waiting time of a car? How will you represent the total waiting time of all the cars for the day? How will you represent the total time that the car wash is open?

In addition to implementing the simulation, write a report for the owners of the Squeaky Clean Car Wash that presents an analysis of your results. (See the Analysis section below for full details.)

You may wish to develop your own design for this program, or you may use the design presented in the Car Wash Design Case Study.


Implementation

Implement the Car Wash Simulation program. A reasonable set of classes for the problem would be:

  • CarWashApplication: Contains the main method.
  • Random: Generates random numbers (java.util.Random).
  • Car: Represents a car (stores the time when the car arrived at the car wash).
  • LLQueue: Stores cars that are currently waiting. (This class from the Queues Mini-Lab #3 provides a cleaner implementation of the Queue abstract data type than do the standard Java classes that implement the java.util.Queue interface.)
  • Bay: Keeps track of whether or not the car wash bay is available and how much longer the current wash will last.
  • CarWashSimulation: Controls the simulation (contains a loop like the one described in the pseudo-code below). Your simulation should re-evaluate the state of the Squeaky Clean Car Wash every minute.

Pseudo-code:

for each minute of the simulation
  if a car arrives
    increment the number of cars that have arrived
    note the arrival time of the car (store this with the car)
    add the car to the queue
  if the car wash bay is empty and there is a car waiting to be washed
    move the car from the queue to the car wash bay
    determine how long that car was waiting and add to total wait time
    start washing the car (bay will be occupied for next 2 minutes)
  otherwise, if there is a car already being washed
    decrease the amount of time left before the bay is available

Question: is there a case missing here that requires any action?


Test-Driven, Iterative Development

Develop and test your program in small increments. For example, you might proceed through the following steps:

Step 1: Construct Car objects and use a queue

Create a Car class that keeps track of a car's arrival time. Have your main method loop a number of times (e.g., 20 times). In each step, print a timestamp and implement the random arrival of a car, putting cars in a queue. Test the queue by stepping through it at the end, printing the arrival time of each car. Your output at this point might look something like:
  time step 0: A car arrived.
  time step 1: No car arrived.
  time step 2: No car arrived.
  time step 3: A car arrived.
  time step 4: A car arrived.
  ...
  Cars in queue:
  Car arrived at time step 0.
  Car arrived at time step 3.
  Car arrived at time step 4.

(You may wish to use the Debug class for printing debugging information.)

Step 2: Develop and test the Bay class

Create a Bay class that tracks a car's progress through the bay, noting how many minutes of delay until the bay is available. When no car is in the bay, the delay is 0. (Tip: Pass the length of a car wash as a parameter so that you can experiment with times other than 3 minutes later.)

You might want to modify your main method to loop through several time steps, but have a car arrive in only one pre-determined step. In each time step, report how long it will be before the car bay is available. For example, you might have:
  time step 0: No car arrived. Bay available in 0 minutes.
  time step 1: A car arrived. Bay available in 3 minutes.
  time step 2: No car arrived. Bay available in 2 minutes.
  time step 3: No car arrived. Bay available in 1 minutes.
  time step 4: No car arrived. Bay available in 0 minutes.

Step 3: Develop and test the CarWashSimulation class

Implement the step method in the simulation class to handle a single minute when the car wash is open. Have the main function run the simulation for a small number of times (for example, 10 minutes) to test your code (especially the calculation of total wait time) on simple cases before trying to simulate an entire day. Update the main function to print the total number of cars serviced, the total wait time for all the cars, and the average wait time.

Step 4: Complete the project

Once the simulation's step method seems to be running correctly, update it to handle cars that are still in the queue when the car wash closes and any other aspects of the original problem description that have not yet been implemented.

If you wish, you may start with the template classes provided for three classes, CarWashSimulation, Car, and Bay, and a very simple class, CarWashApplication, that contains the main function. The locations where you will need to add code have been starred. If you do not wish to use the code provided, you may wish to become familiar with it anyway as a useful supplement to the problem description.


ANALYSIS

Since providing the original problem specification, the owners of the Squeaky Clean Car Wash have asked for some additional information:

  • They would like to know the wait times for their current equipment (4 minutes/wash) as well as the proposed new equipment (3 minutes/wash) for a typical week (7 days, 10 hours per day).
  • They really don't want their customers to have to wait more than ten minutes for a car wash, and would like to know how often such long waits happen in a typical week.

To answer these questions, simulate one week (7 days) of operation. Use your results to write a report that shows the average wait time and the number of cars that would have waited more than ten minutes for each type of machine (four-minute and three-minute wash) for each day in the 7-day period. For example, your output might include a table like the one below, along with a paragraph of explanation and conclusions. (Note that the numbers in the table below are completely made up, and should not be used to validate your results.)

Day 4-Minute Bay 3-Minute Bay
Avg. Wait # Cars With 10 Min Wait Avg Wait # Cars With 10 Min Wait
Monday 18.3 min 4 7.2 min 1
Tuesday ... ... ... ...
Acknowledgments: The behavior of the car wash simulation in this project is based on a project description by Todd Ollendyke.

EVALUATION

Project #2 is worth 30 points. This project will submitted in groups of 2 students. The following items describe the criteria we will use to evaluate your project:

  • Design (5 points):
    • Reasonable design (correct classes & methods implemention; overall program behavior is roughly expected) 3 pts.
    • Use of a queue data structure 2 pts.
  • Functionality (10 points):
    • Program should simulate at least one day 1 pt.
    • Simulate at least 7 days (preferable for report) 1 pt.
    • Car should arrive every 4 minutes, on average 2 pts.
    • Queue should build up when cars arrive less than 4 minutes apart 1 pt.
    • Car wash time should be a parameter to Bay so that it can easily be set to 4 or 3 1 pt.
    • Bay should count down appropriately 1 pt.
    • Cars should only arrive while car wash is open (10 hours or 600 minutes), but program needs to process cars in queue and cars in bay at of day 3 pts.
  • Internal Documentation & Style (5 points):
    • Appropriate internal documentation at top of all files 2 pts.
    • Appropriate internal comments, variable names, indentation in all files 3 pts.
  • Report (10 points):
    • Show daily average wait for 4-minute bay 2 pts.
    • Show daily average wait for 3-minute bay 2 pts.
    • Show number of cars with 10+ minutes wait for the 4-minute bay 1 pt.
    • Show number of cars with 10+ minutes wait for the 3-minute bay 1 pt.
    • Show results for 7 days 2 pts.
    • Include narrative explanation of results 1 pt.
    • Include conclusions or recommendations 1 pt.
  • Note: Make sure these classes are properly implemented, you have clean code, and the appropriate amount of comments.

Submit your completed program through Kit, under Project 2: Car Wash Simulation.

Have fun! And if you have any questions remember my email, my office hours, and the collaboration center are here for you!



← back to the schedule