Question: Write a program named Dice.java that will do the following: 1. Ask the user how many times they wish to roll a pair of
Write a program named Dice.java that will do the following: 1. Ask the user how many times they wish to roll a pair of dice, from 1-999. Validate the input-keep asking until the number is in range. Write a method named getNRolls() to do this step. The method takes a scanner object as its parameter and returns the number of rolls the user desires. 2. Create a 6 x 6 array named rolls to hold the result of the rolls. 3. Simulate randomly rolling a pair of dice as many times as the user requested. As you roll the dice, count how many times each combination of dice was rolled. For example, if the first die is a 3 and the second die is 5, you will add one to the entry at rolls [2][4]. (If you generate numbers in the range 1-6, you will have to subtract one at appropriate places. If you generate numbers in the range 0-5, you don't need to do any subtraction). Write a method named rolldice() to do this step. It takes the number of rolls as its parameter and returns the two-dimensional array of rolls. 4. Print out the array, properly labeled, so that the numbers all line up. You can do this in main() or write a method to do it. 5. Go through the array you created in step 3 and figure out how many times the dice totaled 2, 3, 4. ... 12. Write a method called calcFrequencies ()) to do this. It will take the rolls array as its parameter and return a single- dimensional array of length 11, which your main() method will store in an array named totals. 6. Print the frequency array from step 5, properly labeled. You may do this in main() or write a method to do it. Yes; I know this is "inefficient." It is possible to construct the totals array at the same time that you create the rolls array. You could do everything in main()) without any other methods. However, I want you to practice passing and returning arrays to and from methods, so I decided to write the assignment this way. Sample output:
Step by Step Solution
There are 3 Steps involved in it
Dicejava import javautilRandom import javautilScanner public class Dice method to input the number o... View full answer
Get step-by-step solutions from verified subject matter experts
