Menu

(Solved) : Write Program Java Following Ask User Enter Many Dice Constitute One Roll Based Idea Diffe Q43940623 . . .

Write a program in Java that does thefollowing:

  1. Ask the user to enter how many dice will constitute one roll.(This is based on the idea that different games require differentnumbers of rolls for a “turn”. For example, in Yahtzee, you roll 5dice. In craps, you roll 2 dice. Etc.)
  2. Ask the user to enter how many rolls they would like toperform
  3. Create and use an array to keep track of how many times eachpossible dice sum appears. (Essentially, you need a bunch ofcounters, but how many will depend on how many dice are rolled per”turn”. For example, 2 dice can come up with a total of 2 through12. But 3 dice could yield a total of 3 through 18).
    • Hint: The idea of this array is to be a “frequency array”, likein example 7.7 from the book
    • Hint: How many counters will you need? Well, the lowestpossible total is the number of dice rolled (all 1s). The highestpossible total is all 6s, so (6 * number_of_dice). Use thisinformation to decide on the size of your frequency array.
  4. Use a loop to roll the specified number of dice the desirednumber of times (and calculate the sum of each dice roll). Use thearray to count and track the number of times each possible sumappears
  5. Display the results in a table with 3 columns:
    1. the die total
    2. the number of times that total appeared
    3. the percentage of the total rolls that this sum appeared

    Compute and print the percentage to 2 decimal places.

Sample Run 1

(user input is bolded)

How many dice will constitute one roll? 2How many rolls? 100000Sum # of times Percentage2 2799 2.80 %3 5568 5.57 %4 8261 8.26 %5 10970 10.97 %6 13830 13.83 %7 16862 16.86 %8 13895 13.90 %9 11073 11.07 %10 8391 8.39 %11 5576 5.58 %12 2775 2.78 %

Sample Run 2

(user input is bolded)

How many dice will constitute one roll? 4How many rolls? 100000Sum # of times Percentage4 78 0.08 %5 291 0.29 %6 756 0.76 %7 1490 1.49 %8 2710 2.71 %9 4268 4.27 %10 6309 6.31 %11 8060 8.06 %12 9696 9.70 %13 10866 10.87 %14 11132 11.13 %15 10847 10.85 %16 9649 9.65 % 17 7963 7.96 % 18 6166 6.17 % 19 4331 4.33 %20 2657 2.66 %21 1558 1.56 %22 778 0.78 %23 309 0.31 %24 86 0.09 %

Expert Answer


Answer to Write a program in Java that does the following: Ask the user to enter how many dice will constitute one roll. (This is…

OR