Commit 3bdebf2

mo khan <mo@mokhan.ca>
2019-08-03 22:11:04
calculate final score
1 parent 1399a0b
src/Q8/BadmintonScoring.java
@@ -2,13 +2,32 @@ package Q8;
 
 public class BadmintonScoring {
   private int[][] scores;
-  private static final int PLAYER1=0;
-  private static final int PLAYER2=1;
+  private static final int PLAYER1 = 0;
+  private static final int PLAYER2 = 1;
 
+  public BadmintonScoring(int[][] scores) {
+    this.scores = scores;
+  }
 
-  public int getContinuousPointsPlayer1() { return 0; }
-  public int getContinuousPointsPlayer2() { return 0; }
-  public int getPlayer1Points() { return 0;}
-  public int getPlayer2Points() { return 0;}
-}
+  public int getContinuousPointsPlayer1() {
+    return 0;
+  }
+
+  public int getContinuousPointsPlayer2() {
+    return 0;
+  }
+
+  public int getPlayer1Points() {
+    return this.finalScoreFor(PLAYER1);
+  }
 
+  public int getPlayer2Points() {
+    return this.finalScoreFor(PLAYER2);
+  }
+
+  private int finalScoreFor(int player) {
+    int finalScore = 0;
+    for (int[] items : scores) finalScore = items[player];
+    return finalScore;
+  }
+}
src/Q8/BadmintonScoringTest.java
@@ -0,0 +1,59 @@
+package ca.mokhan.test;
+
+import Q8.*;
+import java.io.*;
+import java.text.*;
+import java.util.*;
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+public class BadmintonScoringTest extends TestCase {
+  private BadmintonScoring subject;
+  private int[][] scores = {
+    {0, 0},
+    {1, 0},
+    {2, 0},
+    {2, 1},
+    {2, 2},
+    {2, 3},
+    {2, 4},
+    {2, 5},
+    {3, 5},
+    {4, 5},
+    {4, 6},
+    {4, 7},
+    {4, 8},
+    {4, 9},
+    {4, 10},
+    {4, 11},
+    {4, 12},
+    {4, 13},
+    {4, 14},
+    {4, 15},
+    {5, 15},
+    {5, 16},
+    {5, 17},
+    {5, 18},
+    {5, 19},
+    {5, 20},
+    {5, 21},
+  };
+
+  public BadmintonScoringTest(String testName) {
+    super(testName);
+    this.subject = new BadmintonScoring(this.scores);
+  }
+
+  public static Test suite() {
+    return new TestSuite(BadmintonScoringTest.class);
+  }
+
+  public void test_getPlayer1Points() {
+    assertEquals(5, this.subject.getPlayer1Points());
+  }
+
+  public void test_getPlayer2Points() {
+    assertEquals(21, this.subject.getPlayer2Points());
+  }
+}
src/Q8/BadmintonScoringWithStroke.java
@@ -9,6 +9,11 @@ public class BadmintonScoringWithStroke {
   private static final int PLAYER1 = 0;
   private static final int PLAYER2 = 1;
 
-  public String getMostUsedStrokePlayer1() { return ""; }
-  public String getMostUsedStrokePlayer2() { return ""; }
+  public String getMostUsedStrokePlayer1() {
+    return "";
+  }
+
+  public String getMostUsedStrokePlayer2() {
+    return "";
+  }
 }
src/Q8/Point.java
@@ -12,7 +12,15 @@ public class Point {
     this.stroke = stroke;
   }
 
-  public int getPlayer() { return 0; }
-  public int getScore() { return 0; }
-  public String getStroke() { return ""; }
+  public int getPlayer() {
+    return 0;
+  }
+
+  public int getScore() {
+    return 0;
+  }
+
+  public String getStroke() {
+    return "";
+  }
 }