In this lab you will write three classes: Die, PairOfDice, and Player. The Die class mimics the rolling of a die. Specifically, this class will implement the following methods: • A default constructor initializing the number of sides of a die to 6. • An overloaded constructor that takes an integer number of sides (assume greater than 1). • roll which generates and returns a random number between 1 and the number of sides (inclusive). • An accessor method to read the value of the face on the die. • A toString method returning the string representation of the face value. The maximum number of sides should be stored as a private constant in the Die class. Also use the Random class for the random number generator. The PairOfDice class mimics the rolling of two dice. Specifically, this class will implement the following methods: • A default constructor that creates and initializes the number of sides of each die to 6. • An overloaded constructor that creates and takes two integer number of sides, one for each die. • roll rolls each die and returns the sum. • An accessor method to read the sum of the dice. The Player class implements the main method which creates the dice pair and rolls them several times reporting the results. For instance, consider the following sample output: Start rolling !! Roll 1: The roll consists of the following: Die 1 has a face value of 4. Die 2 has a face value of 6. And the score is 10 Roll 2: The roll consists of the following: Die 1 has a face value of 5. Die 2 has a face value of 5. And the score is 10 Roll 3: The roll consists of the following: Die 1 has a face value of 6. Die 2 has a face value of 1. And the score is 7 Roll 4: The roll consists of the following: Die 1 has a face value of 3. Die 2 has a face value of 3. And the score is 6
In this lab you will write three classes: Die, PairOfDice, and Player.
The Die class mimics the rolling of a die. Specifically, this class will implement the following methods:
• A default constructor initializing the number of sides of a die to 6.
• An overloaded constructor that takes an integer number of sides (assume greater than 1).
• roll which generates and returns a random number between 1 and the number of sides
(inclusive).
• An accessor method to read the value of the face on the die.
• A toString method returning the string representation of the face value.
The maximum number of sides should be stored as a private constant in the Die class. Also use the
Random class for the random number generator.
The PairOfDice class mimics the rolling of two dice. Specifically, this class will implement the
following methods:
• A default constructor that creates and initializes the number of sides of each die to 6.
• An overloaded constructor that creates and takes two integer number of sides, one for each die.
• roll rolls each die and returns the sum.
• An accessor method to read the sum of the dice.
The Player class implements the main method which creates the dice pair and rolls them several
times reporting the results. For instance, consider the following sample output:
Start rolling !!
Roll 1:
The roll consists of the following:
Die 1 has a face value of 4.
Die 2 has a face value of 6.
And the score is 10
Roll 2:
The roll consists of the following:
Die 1 has a face value of 5.
Die 2 has a face value of 5.
And the score is 10
Roll 3:
The roll consists of the following:
Die 1 has a face value of 6.
Die 2 has a face value of 1.
And the score is 7
Roll 4:
The roll consists of the following:
Die 1 has a face value of 3.
Die 2 has a face value of 3.
And the score is 6
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 4 images