Question
Your task is to create a 'Dice' class which contains an instance of 'Die' as a private variable and simulates the rolling of multiple dice.
Your task is to create a 'Dice' class which contains an instance of 'Die' as a private variable and simulates the rolling of multiple dice.
The code for the original 'Die' class is provided as part of the sample code. You should not touch this code; instead, write your own 'Dice' class according to the specification below.
The 'Dice' class must have 2 constructors:
public Dice(int dice)
This constructor creates an instance of Dice with the specified number of dice. These dice should have the same default number of faces as the 'Die' class (6).
public Dice(int dice, int faces)
This constructor creates an instance of Dice with the specified number of dice, each with faces number of faces. As with the 'Die' class, the minimum number of faces is 3.
The class must also have two other methods, which are similar to the methods of the 'Die' class:
public void RollDice()
This method must roll the dice and store the value resulting from the roll internally.
public int GetFaceValue()
This method must return the result from the last roll of the dice.
Now, given the defaults, the code Dice myDice = new Dice(1); should create a single six-sided die, and rolling this should produce values between 1 and 6.
Dice myDice = new Dice(2, 4);, however, should create two four-sided dice. Rolling these dice should produce values between 2 and 8.
Note that no Main() function is provided. You should create your own Main() function for debugging your new class.
using System; using System.Collections.Generic; using System.Linq; using System.Text;
namespace DiceRoller { ///
private const int SIX_SIDED = 6; private const int DEFAULT_FACE_VALUE = 1; private const int MIN_FACES = 3; ///
public Die() { numFaces = SIX_SIDED; faceValue = DEFAULT_FACE_VALUE; }
///
if (faces >= MIN_FACES) { numFaces = faces; } else { numFaces = SIX_SIDED; }
RollDie(); }
///
///
}// end Class Die
public class Dice { // Implement your 'Dice' class here // ... } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started