User Tools

Site Tools


cs175:arrays_lab_-_sum_of_dice

SumOfDiceArray - Simulate rolling a pair of dice


  • Topics: Arrays, Strings, Loops

Use an array of Strings to implement the SumOfDice program.

Write a program SumOfDiceArray.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 shouldn't need any if statements to track the 11 possible dice sums.

Link to SumOfDiceArray.java (String array)

Link to SumOfDiceArray2.java (int array)


cs175/arrays_lab_-_sum_of_dice.txt · Last modified: 2014/12/09 21:00 by jchung

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki