Commit a04f5ec
Changed files (4)
src/Q8/BadmintonScoring.java
@@ -1,3 +1,11 @@
+/**
+ * Assignment 2, COMP268 Class: BadmintonScoring.java
+ *
+ * @description A class used to keep track of a Badminton game between two opponents.
+ * @author: mo khan Student ID: 3431709
+ * @date August 3, 2019
+ * @version 1.0
+ */
package Q8;
import java.util.*;
@@ -7,22 +15,40 @@ public class BadmintonScoring {
private static final int PLAYER1 = 0;
private static final int PLAYER2 = 1;
+ /**
+ * Creates an instance of the BadmintonScoring object with a 2D array of
+ * scores.
+ *
+ * @param scores a 2D array of scores for each player.
+ */
public BadmintonScoring(int[][] scores) {
this.scores = scores;
}
+ /**
+ * @return the longest point streak for player 1.
+ */
public int getContinuousPointsPlayer1() {
return this.longestStreakFor(PLAYER1);
}
+ /**
+ * @return the longest point streak for player 2.
+ */
public int getContinuousPointsPlayer2() {
return this.longestStreakFor(PLAYER2);
}
+ /**
+ * @return the final score for player 1.
+ */
public int getPlayer1Points() {
return this.finalScoreFor(PLAYER1);
}
+ /**
+ * @return the final score for player 2.
+ */
public int getPlayer2Points() {
return this.finalScoreFor(PLAYER2);
}
src/Q8/BadmintonScoringWithStroke.java
@@ -1,3 +1,11 @@
+/**
+ * Assignment 2, COMP268 Class: BadmintonScoringWithStroke.java
+ *
+ * @description A class used to keep track of a Badminton game between two opponents.
+ * @author: mo khan Student ID: 3431709
+ * @date August 3, 2019
+ * @version 1.0
+ */
package Q8;
import java.util.*;
@@ -7,16 +15,28 @@ public class BadmintonScoringWithStroke extends BadmintonScoring {
private static final int PLAYER1 = 0;
private static final int PLAYER2 = 1;
+ /**
+ * Creates an instance of this class with an ArrayList of points for each
+ * round.
+ *
+ * @param points a list of points for each round
+ */
public BadmintonScoringWithStroke(ArrayList<Point> points) {
super(new int[0][0]);
this.points = points;
this.scores = to2DArray(points);
}
+ /**
+ * @return the name of player 1's preferred stroke.
+ */
public String getMostUsedStrokePlayer1() {
return maxStrokeFor(Point.PLAYER1);
}
+ /**
+ * @return the name of player 2's preferred stroke.
+ */
public String getMostUsedStrokePlayer2() {
return maxStrokeFor(Point.PLAYER2);
}
src/Q8/Point.java
@@ -1,3 +1,11 @@
+/**
+ * Assignment 2, COMP268 Class: Point.java
+ *
+ * @description A class used to represent a point for a single round.
+ * @author: mo khan Student ID: 3431709
+ * @date August 3, 2019
+ * @version 1.0
+ */
package Q8;
public class Point {
@@ -7,20 +15,36 @@ public class Point {
private int score;
private String stroke;
+ /**
+ * Creates an instance of a Point.
+ *
+ * @param player the numeric identifer to identify the player that received the point.
+ * @param stroke the name of the stroke that was used to score the point.
+ * @param score the current score for the player who earned the point.
+ */
public Point(int player, String stroke, int score) {
this.player = player;
this.stroke = stroke;
this.score = score;
}
+ /**
+ * @return the player that scored the point.
+ */
public int getPlayer() {
return this.player;
}
+ /**
+ * @return the score for the player at the time the point was scored.
+ */
public int getScore() {
return this.score;
}
+ /**
+ * @return the stroke used to score the point.
+ */
public String getStroke() {
switch (this.stroke) {
case "a":
src/Q8/README.md
@@ -38,6 +38,11 @@
1. Identify the type of stroke that earned most points for each player.
1. Description of the Code
+
+ The program includes 2 classes, `BadmintonScoring` and `BadmintonScoringWithStroke`.
+ `BadmintonScoringWithStroke` inherits from `BadmintonScoring` and extends it
+ with additional methods for calculating the preferred strokes for each player.
+
1. Errors and Warnings
1. Sample Input and Output
1. Discussion