Your task is to 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 RollDie()
This method must roll the die and store the value resulting from the roll internally - i.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. Your Die class will be instantiated and its methods called by the AMS in order to test it.

If you still have difficulties, here are some tips when writing programs for AMS:

Do not write your program directly into the text box. You should copy and paste the sample code into Visual Studio, write your program there, run it and test it to make sure it works, then paste it into AMS. You only get a limited number of attempts at each AMS exercise, so make sure they count.

Sample Code

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

namespace DieRoller {
/// < summary>
/// Represents one die (singular of dice) with faces showing values between
/// 1 and the number of faces on the die.
/// < /summary>
public class Die {
// Implement your 'Die' class here

}// end Class Die

public class Program {
public static void Main() {
// This will not be called by the AMS, however you may want to test your Die class here.
Die myDie = new Die();
}
}
}
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.