View difference between Paste ID: ak05CSbw and
SHOW:
|
|
- or go back to the newest paste.
| 1 | - | |
| 1 | + | public class PetalGame |
| 2 | {
| |
| 3 | private int d1; | |
| 4 | private int d2; | |
| 5 | private int d3; | |
| 6 | private int d4; | |
| 7 | private int d5; | |
| 8 | ||
| 9 | public PetalGame(int inD1, int inD2, int inD3, int inD4, int inD5) | |
| 10 | {
| |
| 11 | d1 = inD1; | |
| 12 | d2 = inD2; | |
| 13 | d3 = inD3; | |
| 14 | d4 = inD4; | |
| 15 | d5 = inD5; | |
| 16 | } | |
| 17 | ||
| 18 | public int rollDice() | |
| 19 | {
| |
| 20 | return (int) ((Math.random() * 6) + 1); | |
| 21 | } | |
| 22 | ||
| 23 | public void printDice() | |
| 24 | {
| |
| 25 | d1 = rollDice(); | |
| 26 | d2 = rollDice(); | |
| 27 | d3 = rollDice(); | |
| 28 | d4 = rollDice(); | |
| 29 | d5 = rollDice(); | |
| 30 | ||
| 31 | System.out.println("You rolled the following: " + d1 + ", "
| |
| 32 | + d2 + ", " + d3 + ", " + d4 + ", " + d5); | |
| 33 | } | |
| 34 | ||
| 35 | public int calculateAllPetals() | |
| 36 | {
| |
| 37 | int totalPetals = 0; | |
| 38 | ||
| 39 | if (d1 == 3 || d1 == 5) | |
| 40 | totalPetals += d1 - 1; | |
| 41 | if (d2 == 3 || d2 == 5) | |
| 42 | totalPetals += d2 - 1; | |
| 43 | if (d3 == 3 || d3 == 5) | |
| 44 | totalPetals += d3 - 1; | |
| 45 | if (d4 == 3 || d4 == 5) | |
| 46 | totalPetals += d4 - 1; | |
| 47 | if (d5 == 3 || d5 == 5) | |
| 48 | totalPetals += d5 - 1; | |
| 49 | ||
| 50 | return totalPetals; | |
| 51 | } | |
| 52 | } |