Question: Enhance the car wash simulation method in Figure 7.8 so that it has the following additional property. There is an additional parameter, which is a
Enhance the car wash simulation method in Figure 7.8 so that it has the following additional property. There is an additional parameter, which is a maximum length for the queue. When the queue gets as long as this maximum, any customer who arrives will leave without entering the queue (because the customer does not want to wait that long). There should also be one additional simulation result that is printed. In addition to the output shown in Figure 7.8, the method should print the number of simulated customers who left because the queue was too long. Embed the method in a program that allows the user to repeat simulations with different arguments until the user wishes to quit the program.


FIGURE 7.8 Specification and Implementation of the Car Wash Method Specification car WashSimulate public static void carwashSimulate (int washTime, double arrivalProb, int TotalTime) Simulate the running of a car washer for a specified amount of time. Parameters: washTime - the number of seconds required to wash one car arrivalProb - the probability of a customer arriving in any second; for example, 0.1 is 10% totalTime - the total number of seconds for the simulation Precondition: washTime and totalTime are positive; arrivalProb lies in the range 0 to 1. Postcondition: The method has simulated a car wash in which washTime is the number of seconds needed to wash one car, arrivalProb is the probability of a customer arriving in any second, and totalTime is the total number of seconds for the simulation. Before the simulation, the method has written its three parameters to System.out. After the simulation, the method has written two pieces of information to System.out: (1) the number of cars washed, and (2) the average waiting time for customers that had their cars washed. (Customers that are still in the queue are not included in this average.) Throws: I1legalArgumentException Indicates that one of the arguments violates the precondition. Sample Output The carWashSimulate method could be part of an interactive or noninteractive Java program. For example, a noninteractive program might activate carWashSimulate (240, 0.0025, 6000); which can produce this output: Seconds to wash one car: 240 Probability of customer arrival during a second: 0.0025 Total simulation seconds: 6000 Customers served: 13 Average wait: 111.07692307682308 sec The actual output may be different because of variations in the random number generator that is used in the BooleanSource.
Step by Step Solution
3.35 Rating (176 Votes )
There are 3 Steps involved in it
Here is an implementation of the enhanced car wash simulation method in Python import random def car... View full answer
Get step-by-step solutions from verified subject matter experts
