Advertisement
Guest User

Untitled

a guest
Jul 12th, 2016
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. public class Die
  2. {
  3. protected final int MAX = 6; // maximum face value
  4.  
  5. private int x = 0;
  6. private int faceValue; // current value showing on the die
  7.  
  8.  
  9. //-----------------------------------------------------------------
  10. // Constructor: Sets the initial face value.
  11. //-----------------------------------------------------------------
  12. public Die()
  13. {
  14. faceValue = 1;
  15.  
  16. }
  17.  
  18. //-----------------------------------------------------------------
  19. // Rolls the die and returns the result.
  20. //-----------------------------------------------------------------
  21. public int roll()
  22. {
  23. faceValue = (int)(Math.random() * MAX) + 1;
  24.  
  25. return faceValue;
  26. }
  27.  
  28. //-----------------------------------------------------------------
  29. // Face value mutator.
  30. //-----------------------------------------------------------------
  31. public void setFaceValue (int value)
  32. {
  33. faceValue = value;
  34. }
  35.  
  36. //-----------------------------------------------------------------
  37. // Face value accessor.
  38. //-----------------------------------------------------------------
  39. public int getFaceValue()
  40. {
  41. return faceValue;
  42. }
  43.  
  44. //-----------------------------------------------------------------
  45. // Returns a string representation of this die.
  46. //-----------------------------------------------------------------
  47. public String toString()
  48. {
  49. String result = Integer.toString(faceValue);
  50.  
  51. return result;
  52. }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement