Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Your task this week is to create a 'Dice' class which contains a collection of 'Die' as a private variable and simulates the rolling of

Your task this week is to create a 'Dice' class which contains a collection of 'Die' as a private variable and simulates the rolling of multiple dice.

You should include your 'Die' class in the code, in the same namespace as the 'Dice' class, and make a private variable to store an array of these 'Die' in the 'Dice' class.

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), and the same default face value (1).

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, and the same default face value as the 'Die' class (1). 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.

public int GetFaceValue()

This method must return the total face value of all the dice (e.g. if there was 2 dice with face values 3 and 6, this should return 9)

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.

USE CODE:

using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace DiceRoller { public class Die { // You should include your Die class from the previous exercise here }// end class Die public class Dice { // Implement your 'Dice' class here // ... }// end class Dice }

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_2

Step: 3

blur-text-image_step3

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

Genetic Databases

Authors: Martin J. Bishop

1st Edition

ISBN: 0121016250, 978-0121016258

More Books

Students also viewed these Databases questions

Question

6. Explain how to train managers to coach employees.

Answered: 1 week ago