Question

In: Computer Science

You have just been put in charge of safety at your plant. The probability of an...

You have just been put in charge of safety at your plant. The probability of an injury occuring on any given day is p. Your boss says that once the company has 10 totoal days in which at least one injury is reported the insurance premium triples. To plan financially, she wants to know how many days to expect until the insurance premium is going to triple. Write a class called SafetyAnalysis.java that does the following:

a. Reads in a value of p from the user. Checks if it is a double and a feasible probability.

b. Determines if there is an injury each day. To do this, generate a random number between 0 and 1. If the number you generated is less than p then there was an injury. Otherwise, there was not an injury on that day.

c. Continue determining if there was an injury each day until a total of 10 days worth of injuries have occurred (hint: use a loop where you don’t know how many iterations are required).

d. Repeat b. - c. 1000 times (hint: use a loop where you do know how many iterations are required). Return the average number of days it takes until 10 total injuries occur. (hint: each time you complete c., you have a new value to include in your average) e. Report the average number of days over the 1000 experiments that it takes until 10 days of injuries occur. Print this value to the screen with the appropriate labeling information

Solutions

Expert Solution

Source Code in Java:

import java.util.Scanner;
class SafetyAnalysis
{
static boolean isInjury(double p) //method to determine if there is injury on a particular day
{
double injury=Math.random();
if(injury<p)
return true;
else
return false;
}
static int daysTillTenInjuries(double p) //method to return days passed till injury occurs on ten days in the period
{
int days=0,injuries=0;
while(injuries<10)
{
if(isInjury(p))
injuries++;
days++;
}
return days;
}
public static void main(String args[])
{
Scanner in=new Scanner(System.in);
System.out.print("Enter the value of p: "); //input prompt
double p=in.nextDouble(); //input
if(p>=0 && p<=1); //input validation
else
{
System.out.println("The value of p has to be between 0 and 1!");
return;
}
int total=0;
for(int i=0;i<1000;i++) //running the simulation 1000 times
{
total+=daysTillTenInjuries(p);
}
System.out.println("Average days till 10 injuries: "+total/1000.0); //output
}
}

Output:


Related Solutions

You have just been put in charge of estimating the demand for hospital services in a...
You have just been put in charge of estimating the demand for hospital services in a major U.S. city. What economic and noneconomic variables would you include in your analysis? Justify why each variable should be included in the study, and explain how a change in each variable would likely affect the overall demand for hospital services.
We are in mid-October 2020. You have just been put in charge, until July 2021, of...
We are in mid-October 2020. You have just been put in charge, until July 2021, of revenue risk management for a soybean oil producer that processes about 500,000 bushels of soybeans a month (soybeans = input, soybean oil and meal = main outputs). The policy of your predecessor in this job has always been to buy beans on the cash (i.e., spot) market. a. (2.5 points) Before leaving, your predecessor entered into a commodity swap agreement (i.e., a bundle of...
As newly elected President of your school’s Economics Club, you have been put in charge of...
As newly elected President of your school’s Economics Club, you have been put in charge of the Club’s annual budget of $5000. This budget is to be used to produce “services” for the Club’s members (everyone taking this Economics class). In the past, such services have included things like 1) guest speakers coming into class (who charge a fee for speaking); 2) tours of local businesses (transportation costs); 3) downloading economic statistics from the internet (connect time charges); 4) an...
Put It in Writing Activity: Imagine that you have just been hired as the principal of...
Put It in Writing Activity: Imagine that you have just been hired as the principal of a high school where students’ attendance and test performance has been poor and the dropout rate has been high. At a meeting with your teachers, you explain that the principles of classical and operant conditioning could be used to improve the situation. Write a page describing how these principles could be used to increase students’ class attendance, study skills, and test performance. Be sure...
You have just been hired as a financial analyst for Lydex Company, a manufacturer of safety...
You have just been hired as a financial analyst for Lydex Company, a manufacturer of safety helmets. Your boss has asked you to perform a comprehensive analysis of the company’s financial statements, including comparing Lydex’s performance to its major competitors. The company’s financial statements for the last two years are as follows: Lydex Company Comparative Balance Sheet This Year Last Year Assets Current assets: Cash $ 960,000 $ 1,260,000 Marketable securities 0 300,000 Accounts receivable, net 2,700,000 1,800,000 Inventory 3,900,000...
You have just been hired as a financial analyst for Lydex Company, a manufacturer of safety...
You have just been hired as a financial analyst for Lydex Company, a manufacturer of safety helmets. Your boss has asked you to perform a comprehensive analysis of the company’s financial statements, including comparing Lydex’s performance to its major competitors. The company’s financial statements for the last two years are as follows: Lydex Company Comparative Balance Sheet This Year Last Year Assets Current assets: Cash $ 940,000 $ 1,200,000 Marketable securities 0 300,000 Accounts receivable, net 2,620,000 1,720,000 Inventory 3,580,000...
You have just been hired as a financial analyst for Lydex Company, a manufacturer of safety...
You have just been hired as a financial analyst for Lydex Company, a manufacturer of safety helmets. Your boss has asked you to perform a comprehensive analysis of the company’s financial statements, including comparing Lydex’s performance to its major competitors. The company’s financial statements for the last two years are as follows: Lydex Company Comparative Balance Sheet This Year Last Year Assets Current assets: Cash $ 1,020,000 $ 1,260,000 Marketable securities 0 300,000 Accounts receivable, net 2,940,000 2,040,000 Inventory 3,660,000...
You have just been hired as a financial analyst for Lydex Company, a manufacturer of safety...
You have just been hired as a financial analyst for Lydex Company, a manufacturer of safety helmets. Your boss has asked you to perform a comprehensive analysis of the company’s financial statements, including comparing Lydex’s performance to its major competitors. The company’s financial statements for the last two years are as follows: Lydex Company Comparative Balance Sheet This Year Last Year Assets Current assets: Cash $ 1,040,000 $ 1,280,000 Marketable securities 0 300,000 Accounts receivable, net 3,020,000 2,120,000 Inventory 3,680,000...
You have just been hired as a financial analyst for Lydex Company, a manufacturer of safety...
You have just been hired as a financial analyst for Lydex Company, a manufacturer of safety helmets. Your boss has asked you to perform a comprehensive analysis of the company’s financial statements, including comparing Lydex’s performance to its major competitors. The company’s financial statements for the last two years are as follows: Lydex Company Comparative Balance Sheet This Year Last Year   Assets   Current assets:      Cash $ 870,000     $ 1,110,000          Marketable securities 0     300,000          Accounts receivable, net...
You have just been hired as a financial analyst for Lydex Company, a manufacturer of safety...
You have just been hired as a financial analyst for Lydex Company, a manufacturer of safety helmets. Your boss has asked you to perform a comprehensive analysis of the company’s financial statements, including comparing Lydex’s performance to its major competitors. The company’s financial statements for the last two years are as follows: Lydex Company Comparative Balance Sheet This Year Last Year Assets Current assets: Cash $ 930,000 $ 1,170,000 Marketable securities 0 300,000 Accounts receivable, net 2,580,000 1,680,000 Inventory 3,570,000...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT