Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace Dice {
  7. /// <summary>
  8. /// Represents one die (singular of dice) with faces showing values between
  9. /// 1 and the number of faces on the die.
  10. /// </summary>
  11. public class Die {
  12.  
  13.  
  14. private int faces;
  15. private int value;
  16. // Implement your 'Die' class here
  17.  
  18.  
  19. public Die(int faces = 6) {
  20. if (faces < 3) {
  21. this.faces = 6;
  22. }
  23. else {
  24. this.faces = faces;
  25. }
  26. }
  27.  
  28. public void RollDie() {
  29. Random rand = new Random();
  30. value = rand.Next(1, faces + 1);
  31. }
  32.  
  33. public int GetFaceValue() {
  34. return value;
  35. }
  36.  
  37. public int GetNumFaces() {
  38. return faces;
  39. }
  40.  
  41. }// end Class Die
  42.  
  43. public class Program {
  44. public static void Main() {
  45. // This will not be called by the AMS, however you may want to test your Die class here.
  46. Die myDie = new Die();
  47. for (int n = 1; n <= 1000; n++) {
  48. myDie.RollDie();
  49. Console.WriteLine(myDie.GetFaceValue());
  50. }
  51. }
  52. }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement