diff options
| author | mo khan <mo@mokhan.ca> | 2019-08-11 17:36:23 -0600 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2019-08-11 17:36:23 -0600 |
| commit | a04f5ec262de028c843e38bf5864cd84953258b1 (patch) | |
| tree | 7bf48bdc89f0b94e783a0bfeef06b284466832da /src/Q8 | |
| parent | cebbb584d3ec256dea468e73cec5d8a30d3151d9 (diff) | |
add documentation
Diffstat (limited to 'src/Q8')
| -rw-r--r-- | src/Q8/BadmintonScoring.java | 26 | ||||
| -rw-r--r-- | src/Q8/BadmintonScoringWithStroke.java | 20 | ||||
| -rw-r--r-- | src/Q8/Point.java | 24 | ||||
| -rw-r--r-- | src/Q8/README.md | 5 |
4 files changed, 75 insertions, 0 deletions
diff --git a/src/Q8/BadmintonScoring.java b/src/Q8/BadmintonScoring.java index 56c8e40..d3c8b29 100644 --- a/src/Q8/BadmintonScoring.java +++ b/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); } diff --git a/src/Q8/BadmintonScoringWithStroke.java b/src/Q8/BadmintonScoringWithStroke.java index 64dbd7b..183ff05 100644 --- a/src/Q8/BadmintonScoringWithStroke.java +++ b/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); } diff --git a/src/Q8/Point.java b/src/Q8/Point.java index 4b0b86e..391ea28 100644 --- a/src/Q8/Point.java +++ b/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": diff --git a/src/Q8/README.md b/src/Q8/README.md index cd80cfa..c485eaa 100644 --- a/src/Q8/README.md +++ b/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 |
