User Tools

Site Tools


cs175:loops_lab_-_sum_of_dice

SumOfDice - Simulate rolling a pair of dice


Write a program SumOfDice.java that simulates rolling a pair of 6-sided dice 100 times.

The randbetween method will be useful here.

You will need a loop that repeats 100 times.

You will need strings to track the number of dice sums (sum=2 to sum=12).

At the end, print a frequency chart of the dice sums that looks like the following:

Dice Sums:

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

Hints:

  • You'll need a large if, else if, else block to track the 11 possible dice sums.
  • This program is much smaller if an array is used.

Link to SumOfDice.java


cs175/loops_lab_-_sum_of_dice.txt · Last modified: 2014/12/03 21:14 by jchung

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki