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?
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started