Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Dice are used in many tabletop games to implement various game mechanics. Dice come in a variety of shapes and sizes, with four, six, eight,

Dice are used in many tabletop games to implement various game mechanics. Dice come in a variety of shapes and sizes, with four, six, eight, ten, twelve, or twenty sides. Many games need you to assemble a collection of different-sized dice and roll them together. Create a program to imitate dice for a tabletop game.
Create a class for a single dice. The constructor should accept an integer that indicates how many sides the die has. The class should include a function that simulates rolling the die and returns a random number from the valid range.
Create another class that represents a pool of dice. This class should include functions for adding or removing a die from the pool. The class should also include a function that rolls all of the dice in the pool and returns the total that was rolled.
//All commands
add 6
add 4
roll 4
roll 6
add 16
roll 16
roll 16
roll 16
rollall
add 8
add 10
remove 4
rollall
remove 16
remove 6
remove 12
add 2
rollall
Exit
Sample input/output:
Enter Command:
add 6
Adding Dice 6...
Enter Command:
add 4
Adding Dice 4...
Enter Command:
roll 4
Dice 4, Roll Result: 2
Enter Command:
roll 6
Dice 6, Roll Result: 6
Enter Command:
add 16
Adding Dice 16...
Enter Command:
roll 16
Dice 16, Roll Result: 11
Enter Command:
roll 16
Dice 16, Roll Result: 1
Enter Command:
roll 16
Dice 16, Roll Result: 6
Enter Command:
rollall
Rolling all Dice:
Dice 4: Roll Result: 3
Dice 6: Roll Result: 1
Dice 16: Roll Result: 16
Summation of all roll(s): 20.
Enter Command:
add 8
Adding Dice 8...
Enter Command:
add 10
Adding Dice 10...
Enter Command:
remove 4
Removing Dice 4...
Remove Successful: True
Enter Command:
rollall
Rolling all Dice:
Dice 6: Roll Result: 6
Dice 8: Roll Result: 7
Dice 10: Roll Result: 5
Dice 16: Roll Result: 15
Summation of all roll(s): 33.
Enter Command:
remove 16
Removing Dice 16...
Remove Successful: True
Enter Command:
remove 6
Removing Dice 6...
Remove Successful: True
Enter Command:
remove 12
Removing Dice 12...
Remove Successful: False
Enter Command:
add 2
Adding Dice 2...
Enter Command:
rollall
Rolling all Dice:
Dice 2: Roll Result: 1
Dice 8: Roll Result: 1
Dice 10: Roll Result: 9
Summation of all roll(s): 11.
Enter Command:
Exit

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Company Y Company X

Answered: 1 week ago

Question

Describe sources of ethical guidance.

Answered: 1 week ago