230k views
5 votes
Define a single function named displayResults that returns nothing and takes two input parameters, an array of counters and the singular counter for the number of doubles rolled. The function displays the estimated probability of rolling doubles as well as the estimated probability of rolling each of the potential values from 1 to the maximum number that can be rolled (which can be calculated from the aforementioned input parameters). Recall, estimated probability is the calculated estimate of the theoretical probability of a scenario. To calculate an estimated probability we take the number of occurrences for a scenario and divide by the number of possible occurrences (the number of simulations).

User Thush
by
5.0k points

1 Answer

2 votes

Answer:

The function in Java:

public static void displayResult(int outcomes[], int n){

System.out.println("Occurrence\tEstimated Probability");

for(int x : outcomes){

double prob = x/(double)n;

prob = Math.round(prob * 100000.0) / 100000.0;

System.out.println(x+"\t\t"+prob);

}

}

Step-by-step explanation:

See attachment 1 for complete question

This defines the function

public static void displayResult(int outcomes[], int n){

This prints the header

System.out.println("Occurrence\tEstimated Probability");

This iterates through the outcomes

for(int x : outcomes){

This calculates the probability

double prob = x/(double)n;

The probability is then rounded to 5 decimal places

prob = Math.round(prob * 100000.0) / 100000.0;

This prints each occurrence and the estimated probability

System.out.println(x+"\t\t"+prob);

}

}

See attachment 2 for complete program which includes the main

Define a single function named displayResults that returns nothing and takes two input-example-1
User Sam Mason
by
4.9k points