Question: IN JAVA In addition to asking for the number of trials, prompt the user to enter the number of dice to be rolled for the

IN JAVA

In addition to asking for the number of trials, prompt the user to enter the number of dice to be rolled for the trials (so each trial could roll 3 dice, with sums of 3 to 18, or 10 dice, with sums of 10 to 60).

In addition to asking for the number of trials, prompt the user to enter the number of sides that the dice have.

In addition to the table above, add a histogram to the output, using horizontal bars to represent the frequency (see sample below).

Modify your histogram so that if any of the bars would be more than 50 characters long, all bars are scaled down proportionally so they are the correct relative size, with the longest bar being 50 characters long.

Here is my code:

import java.util.Random; import java.util.Scanner;

class Main { public static void main(String[] args) { int[] sumCount = new int[11]; int trials = 0; Scanner scan = new Scanner(System.in); char again = 'y'; int n; while (again == 'y' || again == 'Y') {

System.out.println("Enter the number of trials: "); trials = (int) scan.nextInt(); scan.nextLine(); Random random = new Random(); int diceOne = 0, diceTwo = 0; for (int trial = 1; trial <= trials; trial++) { diceOne = random.nextInt(6) + 1; diceTwo = random.nextInt(6) + 1; int sum = diceOne + diceTwo; sumCount[sum - 2] += 1; } // rolls two dice and

System.out.printf(" %10s%10s%10s ", "Outcome", "Number", "Percent"); for (int i = 0; i < sumCount.length; i++) { System.out.printf("%10d%10d%9.1f%1s ", i + 2, sumCount[i], sumCount[i] * 100.0 / trials, "%"); } // ends for loop it prints out the to the console the outcome, number and percent System.out.println("Again? "); again = scan.nextLine().charAt(0); }// ends while loop } // ends main method } // end class

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!