# Class Activities Week 6 Lecture 2

## Exercise 1: `Die`

Class

Implement the following `Die`

class:

Die |

- DEFAULT_NUMBER_OF_SIDES: int = 6 {readOnly} - numberOfSides: int - generator: Random {readOnly} |

+Die() +Die(numberOfSides: int) +roll(): int |

## Exercise 2: Six-Sided Die

Create a 6-sided die, roll it 100 times, and display the sum of all the rolls.

## Exercise 3: Dice Battle

Create a 10-sided die and a 20-sided die. Roll the 10-sided die twice and the 20-sided die once. Indicate whether the single roll of the 20-sided die exceeds the two rolls of the 10-sided die.

## Exercise 4: Dice Battles

Write a program performs the comparison in the previous example 100 times. Display the percentage of times that the 20-sided die roll wins.

## Exercise 5: Six-Sided Distribution

Create a 6-sided die. Roll it 10,000 times. Display how many times each value (1, 2, 3, 4, 5, and 6) was rolled.

## Exercise 6: Setting the Random number seed

Modify the `Die`

class so that the `Random`

object is created with a seed of 1234. Then
redo the previous exercise six times and compare the results.

## Exercise 7: Seeds

Experiment with different seed values. Try to find a seed value that results in 1 being rolled most frequently. Then repeat for 2, 3, 4, 5, and 6.