PLEASE HELP WITH JAVA Youve been hired by Cube Counters to w

PLEASE HELP WITH JAVA!

You\'ve been hired by Cube Counters to write a Java console application that repeatedly rolls two ten-sided dice and tabulates the results. To roll the dice, randomly generate two numbers between 1 and 10. Add the two numbers together and increment the counter for that sum. Possible sums range from 2 to 20 so store the counters in an integer array of 19 elements. Roll the dice 100,000 times. Format the output in three columns with the first column containing a sum, the second column containing the count, and the third column containing the percentage of that count over 100,00. Print the total rolls and percentage. These should be 100,000 and 100%, respectively. Format the counts with commas. Format the percentages with two decimal places.
PLEASE HELP WITH JAVA!

You\'ve been hired by Cube Counters to write a Java console application that repeatedly rolls two ten-sided dice and tabulates the results. To roll the dice, randomly generate two numbers between 1 and 10. Add the two numbers together and increment the counter for that sum. Possible sums range from 2 to 20 so store the counters in an integer array of 19 elements. Roll the dice 100,000 times. Format the output in three columns with the first column containing a sum, the second column containing the count, and the third column containing the percentage of that count over 100,00. Print the total rolls and percentage. These should be 100,000 and 100%, respectively. Format the counts with commas. Format the percentages with two decimal places.

You\'ve been hired by Cube Counters to write a Java console application that repeatedly rolls two ten-sided dice and tabulates the results. To roll the dice, randomly generate two numbers between 1 and 10. Add the two numbers together and increment the counter for that sum. Possible sums range from 2 to 20 so store the counters in an integer array of 19 elements. Roll the dice 100,000 times. Format the output in three columns with the first column containing a sum, the second column containing the count, and the third column containing the percentage of that count over 100,00. Print the total rolls and percentage. These should be 100,000 and 100%, respectively. Format the counts with commas. Format the percentages with two decimal places.

Solution

import java.util.Random;
public class Cubes{
   public static void main(String args[]){
       Random rand = new Random();
       int m,n,sum;
       int tr = 100000;
       int[] counter = new int[19];
       for(int i=0;i<tr;i++){
           // get two random number between 1 and 10.
           m = rand.nextInt(10)+1;
           n = rand.nextInt(10)+1;
           sum = m+n;
           // increment counter of sum-2 index.
           counter[sum-2] = counter[sum-2]+1;
       }
       System.out.println(\"SUM,Count,Percentage\");
       for(int i=0;i<19;i++){
           System.out.println((i+2)+\",\"+counter[i]+\",\"+((counter[i]*100.0)/tr));
       }
       System.out.println(\"Total rolls:\"+tr+\"\ Total Percentage:\"+100);

   }
}
/*
Sample output
SUM,Count,Percentage
2,968,0.968
3,2038,2.038
4,3061,3.061
5,3954,3.954
6,4944,4.944
7,6000,6.0
8,7122,7.122
9,7981,7.981
10,8991,8.991
11,10070,10.07
12,9013,9.013
13,8175,8.175
14,7026,7.026
15,5913,5.913
16,4902,4.902
17,3999,3.999
18,2914,2.914
19,1940,1.94
20,989,0.989
Total rolls:100000
Total Percentage:100
*/

 PLEASE HELP WITH JAVA! You\'ve been hired by Cube Counters to write a Java console application that repeatedly rolls two ten-sided dice and tabulates the resul

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site