Skip to content

Dice

Create a class to represent a die (a single dice). This can have a number of sides, which cannot change after it is created. The die will also have a current value, being the value visible on top when the die is rolled. The die can be rolled, which randomises the value shown on top based on the number of sides. The current value can be read, but not changed by other code. Include a method to print the details of the die, including its sides and current value so that it can be shown in the test code.

Sides: 6
1: Roll die
2: Get new die
3: Quit
> 1
6 sides: value is 4
1: Roll die
2: Get new die
3: Quit
> 1
6 sides: value is 2
1: Roll die
2: Get new die
3: Quit
> 1
6 sides: value is 6
1: Roll die
2: Get new die
3: Quit
> 2
Sides: 20
1: Roll die
2: Get new die
3: Quit
> 1
20 sides: value is 12