wangmaster

Untitled

Nov 5th, 2016
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1.  
  2. /**
  3. * Write a description of class DiceRoll here.
  4. *
  5. * @author (your name)
  6. * @version (a version number or a date)
  7. */
  8. public class PairOfDice {
  9.  
  10. private int die1; // Number showing on the first die.
  11. private int die2; // Number showing on the second die.
  12.  
  13. public PairOfDice() {
  14. // Constructor. Rolls the dice, so that they initially
  15. // show some random values.
  16. roll(); // Call the roll() method to roll the dice.
  17. }
  18.  
  19. public void roll() {
  20. // Roll the dice by setting each of the dice to be
  21. // a random number between 1 and 6.
  22. die1 = (int)(Math.random()*6) + 1;
  23. die2 = (int)(Math.random()*6) + 1;
  24. }
  25.  
  26. public int getDie1() {
  27. // Return the number showing on the first die.
  28. return die1;
  29. }
  30.  
  31. public int getDie2() {
  32. // Return the number showing on the second die.
  33. return die2;
  34. }
  35.  
  36. public int getTotal() {
  37. // Return the total showing on the two dice.
  38. return die1 + die2;
  39. }
  40.  
  41. }
Add Comment
Please, Sign In to add comment