Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Task Write a program that asks the user how many times they want to roll two 6-s

ID: 3639240 • Letter: T

Question

Task

Write a program that asks the user how many times they want to roll two 6-sided dice. Once this has been obtained, repeatedly "roll" the two dice as many times as the user requested; display the values rolled by each pair. Upon each roll, calculate the value rolled (i.e., add up the two dice values). Your program should calculate and display a histogram of the frequency of the values generated. The histogram should display the bar graphs from 2-12 based upon how many times that value was rolled.

Be sure to comment your program well.

Here is a sample output (assuming the user entered 50):

Enter how many times to roll the dice: 50
0 : I rolled a 2 and a 4
1 : I rolled a 1 and a 5
2 : I rolled a 6 and a 5
3 : I rolled a 3 and a 4
4 : I rolled a 5 and a 6
5 : I rolled a 1 and a 6
6 : I rolled a 2 and a 1
7 : I rolled a 5 and a 2
8 : I rolled a 4 and a 4
9 : I rolled a 4 and a 4
10 : I rolled a 4 and a 1
11 : I rolled a 3 and a 4
12 : I rolled a 4 and a 6
13 : I rolled a 4 and a 2
14 : I rolled a 2 and a 1
15 : I rolled a 2 and a 6
16 : I rolled a 4 and a 6
17 : I rolled a 5 and a 6
18 : I rolled a 4 and a 4
19 : I rolled a 4 and a 2
20 : I rolled a 2 and a 6
21 : I rolled a 6 and a 2
22 : I rolled a 5 and a 2
23 : I rolled a 2 and a 6
24 : I rolled a 5 and a 3
25 : I rolled a 2 and a 2
26 : I rolled a 2 and a 4
27 : I rolled a 2 and a 6
28 : I rolled a 1 and a 3
29 : I rolled a 2 and a 1
30 : I rolled a 2 and a 4
31 : I rolled a 5 and a 2
32 : I rolled a 6 and a 6
33 : I rolled a 5 and a 5
34 : I rolled a 2 and a 3
35 : I rolled a 1 and a 4
36 : I rolled a 2 and a 2
37 : I rolled a 3 and a 2
38 : I rolled a 1 and a 1
39 : I rolled a 5 and a 6
40 : I rolled a 6 and a 4
41 : I rolled a 1 and a 4
42 : I rolled a 1 and a 2
43 : I rolled a 3 and a 6
44 : I rolled a 3 and a 1
45 : I rolled a 6 and a 6
46 : I rolled a 3 and a 1
47 : I rolled a 2 and a 5
48 : I rolled a 2 and a 5
49 : I rolled a 5 and a 3

Histogram of rolls:
2 : *
3 : ****
4 : *****
5 : *****
6 : ******
7 : ********
8 : **********
9 : *
10 : ****
11 : ****
12 : **

Explanation / Answer

Here ya go! import java.util.Scanner; import java.util.Random; public class Test { public static void main(String args[]) { Scanner in = new Scanner(System.in); Random generator = new Random(); int numRolls = 0; int counter[] = new int[13]; // Get how many times to roll System.out.print("Enter how many times to roll the dice: "); numRolls = in.nextInt(); // Generate the tosses and print the results for(int i=0; i
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote