Queues
This program is a car wash simulation. The queue is used to track how
long a car waits in line.
arguments
This program must take three command line arguements, in the correct
order. They are :
- how long the car wash is open ( in hours )
- how many minutes it takes to wash a car
- and what the percentage chance of a car arriving is per minute
( as an int value 0-100 )
There will be no other input to the program. You need to check the
arguments for the number and type. If there are any problems, output an
appropriate error message, and exit with a non-zero value. To check the
return code from the last command type "echo $?".
program logic
While the car wash is open, you need to do the following every minute.
- See if a new car arrives, if it does put in the line of cars.
- If you are not washing a car and there is a car waiting,
get one from the line of cars so you can wash it.
- If there is a car to wash, do so.
When the car wash closes you still need to wash all of the cars in
the line.
The output should display whenever a car arrives, whenever you start
washing a car, and how many cars are in line when you close ( quit
accepting new cars ). When the carwash stops accepting new cars, state
how many are waiting to be washed. You also need to tell me two things
at the end of the program : how many cars were washed, and what the
average wait time in the line was ( as a floating point number ).
the queue
For our purposes a car is nothing more that its arrival time.
So the queue just needs to store ints.
NOTE: Your queue MUST use dynamic mememory.
program output
The output should be formatted like the file at this link.
Use the same information and format as I did.
Each event must be on its own line and start with the time it occurred.
At closing tell me how many are still waiting to be washed.
At the end of the program you need to tell me how many cars were washed,
and what the average wait time was ( as a floating point value ).
This program is due on July 21st.
useful Java API calls
- Integer.parseInt
- Random.nextInt
- System.exit
The Goals
- Write and use a queue class
- Solve a simple queue problem
- Use dynamic memory
- Use command line arguments