CAR WASH SIMULATION
PROJECT
By Autumn C. Spaulding with Alyce Brady
•
Edited by Sandino Vargas-Pérez
PROBLEM DESCRIPTION
Construct a simulation of a car wash to determine the average waiting time during a typical day (9 am to 7 pm) using different types of equipment. See the Car Wash Design Exercise for a full description of the Car Wash Simulation we wish to develop.
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 themain
method. -
Random
: Generates random numbers (java.util.Random
). -
Car
: Represents a car (stores the time when the car arrived at the car wash). -
K_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 thejava.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 | ... | ... | ... | ... |
Optional Enhancement
Another alternative that the car wash owners are considering is to add a second bay similar to the one they have now, with a single line that serves them both. Customers would wait in the one line and enter the next available bay to get their car washed. What changes would you have to make to the main program to make this work? What changes will you have to make to your other classes?
Modify your program to handle multiple bays, and update your report to show what the results of having two bays would be. Run your analysis on the new setup. Could they handle twice as many cars with the same average wait time they have now?
Submit your completed program through Kit, under Car Wash Simulation Project.
Have fun! And if you have any questions remember I am available through email, Teams, and my office hours. And don't forget the Collaboration Center, which is a great place to work and ask questions too!
← back to the schedule