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

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

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

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 4 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY