Guest User

Untitled

a guest
Apr 27th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. package P91;
  2. import java.util.Random;
  3.  
  4. /**
  5. This class models a die that, when cast, lands on a random
  6. face.
  7. */
  8. public class Die implements Measurable
  9. {
  10. /**
  11. Constructs a die with a given number of sides.
  12. @param s the number of sides, e.g. 6 for a normal die
  13. */
  14. public Die(int s)
  15. {
  16. sides = s;
  17. generator = new Random();
  18. }
  19.  
  20. /**
  21. Simulates a throw of the die
  22. @return the face of the die
  23. */
  24. public int cast()
  25. {
  26. return 1 + generator.nextInt(sides);
  27. }
  28. /**
  29. * A somewhat arbitrary method that just returned the exact same thing that cast did...
  30. * @return A dice roll int
  31. */
  32. public int getMeasure()
  33. {
  34. return this.cast();
  35. }
  36.  
  37. private Random generator;
  38. private int sides;
  39. private int count;
  40. private int sum;
  41. }
Add Comment
Please, Sign In to add comment