Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Using C# code. Read the instructions below carefully. Also the system should handle faces below minimum. Use the sample code format below; Sample code: using

Using C# code. Read the instructions below carefully. Also the system should handle faces below minimum. Use the sample code format below;

image text in transcribed

Sample code:

using System; using System.Collections.Generic; using System.Linq; using System.Text;

namespace DieRoller { ///

/// Represents one die (singular of dice) with faces showing values between /// 1 and the number of faces on the die. ///

public class Die { // Implement your 'Die' class here

}// end Class Die

public class Program { public static void Main() { // test your Die class here. Die myDie = new Die(); } } }

Create a "Die" Class which will allow for the rolling of a single die, which can have a variable number of sides, and the number of sides is passed to the die on construction. The Die' class should have two private attributes. One which stores the number of faces (numFaces), and one which stores the current face value of the dice (faceValue) i.e. the face that is currently showing on the dice The Die' class must have 2 constructors: public Die() This constructor creates an instance of Die with the default number of faces, which is 6. The face value should be set to the default face value, which is 1 public Die(int faces) This constructor creates an instance of Die with a specific number of faces. If'faces' is less than the minimum number of faces (3), the default number of faces is instantiated (6) The face value should be set to the default face value (1). The class must also have three other methods to represent common behaviours of a die public void Rol1Die() This method must roll the die and store the value resulting from the roll internally .e. the new face value. Hint the Random class will be helpful here. public int GetFaceValue) This method should be used to get the current face value of the die public int GetNumFaces() This method should be used to get the number of faces of the die. Now, given the defaults, the code Die myDie = new Die() ; should create a single six-sided die, with a face value of 1 Die myDie new Die(10);, however, should create a 10-sided Die. Rolling this die should produce values between 1 and 10 Note that no Main) function is provided. You should create your own Main() function for debugging your new class

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_2

Step: 3

blur-text-image_3

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

Big Data Fundamentals Concepts, Drivers & Techniques

Authors: Thomas Erl, Wajid Khattak, Paul Buhler

1st Edition

0134291204, 9780134291208

More Books

Students also viewed these Databases questions