Commit 82589bb
Changed files (3)
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;
+ }
}
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);
+ }
+}
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;