diff options
| author | mo <mo.khan@gmail.com> | 2019-06-18 16:27:29 -0600 |
|---|---|---|
| committer | mo <mo.khan@gmail.com> | 2019-06-18 16:27:29 -0600 |
| commit | 82589bb93e5b3d7a4c99394c1486c08e1d63eec4 (patch) | |
| tree | dbc111cd4c92eace419b9e98d58c860d1b30d005 /src/Q4 | |
| parent | 717a1964133f05eb9d39e879f2ed27ebb054cdb2 (diff) | |
try to understand how this confusing, untestable api is supposed to work
Diffstat (limited to 'src/Q4')
| -rw-r--r-- | src/Q4/README.md | 4 | ||||
| -rw-r--r-- | src/Q4/RandomSumGame.java | 20 | ||||
| -rw-r--r-- | src/Q4/RandomSumGameTest.java | 24 |
3 files changed, 44 insertions, 4 deletions
diff --git a/src/Q4/README.md b/src/Q4/README.md index 355bc0d..f2a0455 100644 --- a/src/Q4/README.md +++ b/src/Q4/README.md @@ -7,7 +7,9 @@ Student ID: 3431709 ```text Craps is a dice game where two dice are rolled. -Each die has six faces representing values 1, 2, 3, 4, 5, or 6. +Each die has six faces representing values: + +1, 2, 3, 4, 5, or 6. 1. If the sum is 2, 3, or 12 (called craps), you lose; 2. If the sum is 7 or 11 (called natural), you win; diff --git a/src/Q4/RandomSumGame.java b/src/Q4/RandomSumGame.java index 823c32e..e5b6ce0 100644 --- a/src/Q4/RandomSumGame.java +++ b/src/Q4/RandomSumGame.java @@ -1,5 +1,7 @@ package Q4; +import java.util.*; + public class RandomSumGame { private boolean start; private int d1; @@ -8,7 +10,19 @@ public class RandomSumGame { private int valuePoint; private String status; - public void play(int d1, int d2) { } - public void play() { } - public void rollDice() {} + public void play(int d1, int d2) {} + + public void play() { + this.rollDice(); + this.play(this.d1, this.d2); + } + + public void rollDice() { + this.d1 = this.roll(); + this.d2 = this.roll(); + } + + private int roll() { + return new Random().nextInt(5) + 1; + } } diff --git a/src/Q4/RandomSumGameTest.java b/src/Q4/RandomSumGameTest.java new file mode 100644 index 0000000..3a5e26c --- /dev/null +++ b/src/Q4/RandomSumGameTest.java @@ -0,0 +1,24 @@ +package ca.mokhan.test; + +import Q4.*; +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +public class RandomSumGameTest extends TestCase { + private RandomSumGame subject; + + public RandomSumGameTest(String testName) { + super(testName); + this.subject = new RandomSumGame(); + } + + public static Test suite() { + return new TestSuite(RandomSumGameTest.class); + } + + public void test_play() { + subject.play(); + assertTrue(true); + } +} |
