Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions