Java Lets roll some dice! Write a program that allows the user to choose to roll
ID: 3767028 • Letter: J
Question
Java
Lets roll some dice! Write a program that allows the user to choose to roll between 1 and 100 dice between 1 and 1000 times. The program should simulate each roll of the die/dice by generating one random number representing the total value of the roll. The range of possible values will be based on the number of dice specified. For example: for 1 die generate one random number between 1 and 6; for 4 dice generate one random number between 4 and 24. The program should use an array to keep count of the number of times each possible total is rolled. For example, if rolling 1 die the array values will represent how many times a 1 is rolled, how many times a 2 is rolled, how many times a 3 is rolled, how many times a 4 is rolled, how many times a 5 is rolled, how many times a 6 is rolled….if rolling 3 dice, the array values will represent how many times a 3 through 18 is rolled. (Note: the array does not store the values that are being rolled – instead each value in the array is a count of how many times the value associated with the index has been rolled.) After all the rolls are complete the program should print the results in a histogram where each roll is represented by a *. The histogram should be printed to the screen and to a file. There should be a separate file for each “try” in the program session. These files can be overwritten with each run of the program. The program should contain a separate method that is used to print out the histogram. Below the histogram on the screen, the program should print out a statement indicating which number or numbers was rolled the most. If more than one number was rolled the maximum number of times the program should display each of the numbers. The program should contain a separate method to determine these results. The user should be able to “play” as many times as they like.
Here are some examples of output:
(The users input is in bold)
----jGRASP exec: java RollDice
You may roll up to 100 dice. How many dice would you like to roll? 1
You may roll the dice up to 1000 times. How many times would you like to roll the dice? 100
1 *****************
2 ********************
3 ****************
4 ********
5 ******************
6 *********************
Number(s) rolled most often: 6
Try again? (yes/no): yes
You may roll up to 100 dice. How many dice would you like to roll? 2
You may roll the dice up to 1000 times. How many times would you like to roll the dice? 100
2 ***********
3 **********
4 **********
5 ******
6 ***********
7 *********
8 *******
9 ***********
10 **********
11 **********
12 *****
Number(s) rolled most often: 2 6 9
Try again? (yes/no):
Explanation / Answer
#include #include /* function main begins program execution */ int main(void) { int frequency1 = 0; /* rolled 1 counter */ int frequency2 = 0; /* rolled 2 counter */ int frequency3 = 0; /* rolled 3 counter */ int frequency4 = 0; /* rolled 4 counter */ int frequency5 = 0; /* rolled 5 counter */ int frequency6 = 0; /* rolled 6 counter */ int roll; /* roll counter, value 1 to 6000 */ int face; /* represents one roll of the die, value 1 to 6 */ /* loop 6000 times and summarize results */ for (roll = 1; rollRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.