Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Write a program in Java that does the following:

  1. Ask the user to enter how many dice will constitute one roll. (This is based on the idea that different games require different numbers of rolls for a "turn". For example, in Yahtzee, you roll 5 dice. In craps, you roll 2 dice. Etc.)
  2. Ask the user to enter how many rolls they would like to perform
  3. Create and use an array to keep track of how many times each possible dice sum appears. (Essentially, you need a bunch of counters, 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 through 12. But 3 dice could yield a total of 3 through 18).
    • Hint: The idea of this array is to be a "frequency array", like in example 7.7 from the book
    • Hint: How many counters will you need? Well, the lowest possible total is the number of dice rolled (all 1s). The highest possible total is all 6s, so (6 * number_of_dice). Use this information to decide on the size of your frequency array.
  4. Use a loop to roll the specified number of dice the desired number of times (and calculate the sum of each dice roll). Use the array to count and track the number of times each possible sum appears
  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? 2 How many rolls? 100000 Sum # of times Percentage 2 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? 4 How many rolls? 100000 Sum # of times Percentage 4 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 % 

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_2

Step: 3

blur-text-image_3

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

Data Management Databases And Organizations

Authors: Richard T. Watson

3rd Edition

0471418455, 978-0471418450

More Books

Students also viewed these Databases questions

Question

Is the person willing to deal with the consequences?

Answered: 1 week ago