Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package P91;
- import java.util.Random;
- /**
- This class models a die that, when cast, lands on a random
- face.
- */
- public class Die implements Measurable
- {
- /**
- Constructs a die with a given number of sides.
- @param s the number of sides, e.g. 6 for a normal die
- */
- public Die(int s)
- {
- sides = s;
- generator = new Random();
- }
- /**
- Simulates a throw of the die
- @return the face of the die
- */
- public int cast()
- {
- return 1 + generator.nextInt(sides);
- }
- /**
- * A somewhat arbitrary method that just returned the exact same thing that cast did...
- * @return A dice roll int
- */
- public int getMeasure()
- {
- return this.cast();
- }
- private Random generator;
- private int sides;
- private int count;
- private int sum;
- }
Add Comment
Please, Sign In to add comment