Enhance the car wash simulation method in Figure 7.8 so that it has the following additional property.
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 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 Answer:
Here is an implementation of the enhanced car wash simulation method in Python import random def car...View the full answer
Students also viewed these Computer science questions
-
You, CA, are the audit senior of Ball Construction Corporation (BC), a small public company. It is September 19, 2013, and the year-end audit fieldwork has just been completed. The audit partner,...
-
Global Touch Corporation (GTC) is one of Canada's largest public companies. GTC provides end users with networking capabilities through its system of copper and coaxial cable lines. GTC operates in...
-
1. A firm consists of 600 acres of land, of which 500 acres will be planted with corn, soybeans, and wheat according to this condition: -At least half of the planted acreage should be in corn - No...
-
Head movement evaluations are important because disabled individuals may be able to operate communications aids using head motion. The paper Constancy of Head Turning Recorded in Healthy Young Humans...
-
Annual values of Canadian exports to Europe and to the areas designated Far East/Oceania (in millions of dollars) were collected in independent random samples: Far East/Oceania: 19,407 16,889 16,688...
-
Thorium-232 is an a emitter with 14-billion-year half-life. Radium-228 is a ? - emitter with 5.75-year half-life. Actinium-228 is a ? - emitter with 6.13-hour half-life.(a) What?s the third daughter...
-
You sell a brand of thermostat that has a life expectancy that is normally distributed, with a mean life of 8.5 years and a standard deviation of 0.75 years. You want to give a guarantee for free...
-
Ms. Shlemeel was the sole proprietor of a business that retailed specialty coffees. The business has a December 31 year-end. With the advice of her lawyer, Mr. Shlemozzel, she proposes to transfer...
-
Sure Tool Company is expected to pay a dividend of $2 in the upcoming year. The risk-free rate of return is 4%, and the expected return on the market portfolio is 14%. Analysts expect the price of...
-
Precision Corporation was organized on January 1, 2018. At the end of 2018, the company had not yet employed an accountant; however, an employee who was ?good with numbers? prepared the following...
-
In Figure 7.3, we presented a program that checks a string to see if the letters in the string read the same forward and backward. The previous exercise performed a similar check using words in place...
-
Give a complete implementation of a priority queue using an array of ordinary queues. For your ordinary queue, use the version from edu.colorado.collections.ArrayQueue in Figure 7.9. FIGURE 7.9...
-
a. Find the area of the surface cut from the hemisphere x 2 + y 2 + z 2 = 4, z 0, by the cylinder x 2 + y 2 = 2x. b. Find the area of the portion of the cylinder that lies inside the hemisphere. X...
-
Identify four of the most expensive medical conditions for employers.
-
What are the characteristics of effective communication in the healthcare setting?
-
What is the difference between a spokesperson and a character representative? Define the different options. When should each be used if at all?
-
How do health communicators select the channel of communication for their messages? What factors must be considered?
-
Why are synergistic visual and verbal elements important to IMC?
-
Karl purchased his residence on January 2, 2015, for $260,000, after having lived in it during 2014 as a tenant under a lease with an option to buy clause. On August 1, 2016, Karl sells the residence...
-
Several months have passed and the Managing Partner approved and properly filed the Complaint and properly submitted the Request for Production of Documents that you drafted. In fact, it has been 75...
-
Given an undirected graph G with V vertices and E edges, the sum of the degrees of all vertices is A. E B. 2E C. V D. 2V
-
What are weighted graphs?
-
Consider an undirected random graph of eight vertices. The probability that there is an edge between a pair of vertices is 1/2. What is the expected number of unordered cycles of length three? A. A...
-
How do you prioritize features and attributes when designing a new product or service? What steps should be taken to ensure that the design process aligns with the organization's overall strategy and...
-
Information that does not have an adjustment reason code to route payments into the correct bank accounts to relay about patient benefit coverage to indicate the amount being paid and the date of...
-
Superior Company provided the following data for the year ended December 31 (all raw materials are used in production as direct materials): Selling expenses Purchases of raw materials Direct labor...
Study smarter with the SolutionInn App