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).

Respuesta :

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);

   }

}

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

Ver imagen MrRoyal
Ver imagen MrRoyal