diff --git a/src/code/ca/bcit/comp2522/lab06/EligibilityRule.java b/src/code/ca/bcit/comp2522/lab06/EligibilityRule.java index 7001529..33ea238 100644 --- a/src/code/ca/bcit/comp2522/lab06/EligibilityRule.java +++ b/src/code/ca/bcit/comp2522/lab06/EligibilityRule.java @@ -1,6 +1,22 @@ package ca.bcit.comp2522.lab06; +/** + * EligibilityRule is a way to enforce defined rules of a + * HockeyPlayer + * + * @author Braeden Sowinski + * @author Nico Agostini + * @author Trishaan Shetty + * @author Calvin Arifianto + * @version 1.0.0 +*/ @FunctionalInterface public interface EligibilityRule { + /** + * isEligible method. + * + * @param player A hockey player + * @return True or False. True if player is eligible, false otherwise. + */ boolean isEligible(HockeyPlayer player); } \ No newline at end of file diff --git a/src/code/ca/bcit/comp2522/lab06/HockeyPlayer.java b/src/code/ca/bcit/comp2522/lab06/HockeyPlayer.java index f963d94..4f68c6e 100644 --- a/src/code/ca/bcit/comp2522/lab06/HockeyPlayer.java +++ b/src/code/ca/bcit/comp2522/lab06/HockeyPlayer.java @@ -1,51 +1,77 @@ package ca.bcit.comp2522.lab06; /** - * HockeyPlayer holds information of a - * hockey player and their simple stats. + * Represents a hockey player and their basic statistics, including name, position, + * year of birth, and total goals scored. + * + *
This class validates all input parameters to ensure + * that player data is always initialized correctly.
* - * @author Braeden Sowinski * @author Nico Agostini + * @author Braeden Sowinski * @author Trishaan Shetty * @author Calvin Arifianto * @version 1.0.0 */ -public class HockeyPlayer { - private static String FORWARD = "F"; - private static String DEFENCE = "D"; - private static String GOALIE = "G"; +public class HockeyPlayer +{ + private static final String FORWARD = "F"; + private static final String DEFENCE = "D"; + private static final String GOALIE = "G"; private final String name; private final String position; - private final int yearOfBirth; - private final int goals; + private final int yearOfBirth; + private final int goals; + /** + * Validates a string to ensure it is not null or empty. + * + * @param str the string to validate + * @throws IllegalArgumentException if the string is null or empty + */ private static void validateString(final String str) - throws IllegalArgumentException + throws IllegalArgumentException { if (str == null || str.isEmpty()) { - throw new IllegalArgumentException("invalid string"); + throw new IllegalArgumentException("Invalid string: cannot be null or empty."); } } + /** + * Validates a player's position to ensure it matches one of the accepted + * values: F, D, or G. + * + * @param positionToValidate the position to validate + * @throws IllegalArgumentException if the position is invalid + */ private void validatePosition(final String positionToValidate) + throws IllegalArgumentException { - - if (position != null && - ( position.equals(FORWARD) - || position.equals(DEFENCE) - || position.equals(GOALIE))) + if (positionToValidate == null + || !(positionToValidate.equals(FORWARD) + || positionToValidate.equals(DEFENCE) + || positionToValidate.equals(GOALIE))) { - throw new IllegalArgumentException("Position not accepted."); + throw new IllegalArgumentException("Position not accepted: must be F, D, or G."); } } + /** + * Constructs a new HockeyPlayer with the specified attributes. + * + * @param name the name of the player + * @param position the player's position (F, D, or G) + * @param yearOfBirth the year the player was born + * @param goals the total number of goals scored by the player + * @throws IllegalArgumentException if the name or position are invalid + */ public HockeyPlayer( - final String name, - final String position, - final int yearOfBirth, - final int goals + final String name, + final String position, + final int yearOfBirth, + final int goals ) { validateString(name); validatePosition(position); @@ -56,24 +82,55 @@ public class HockeyPlayer { this.goals = goals; } - protected String getPlayerName(){ + /** + * Returns the player's name. + * + * @return the player's name + */ + protected String getPlayerName() + { return this.name; } - protected String getPosition(){ + /** + * Returns the player's position. + * + * @return the player's position + */ + protected String getPosition() + { return this.position; } - protected int getGoals(){ + /** + * Returns the number of goals scored by the player. + * + * @return the number of goals + */ + protected int getGoals() + { return this.goals; } - protected int getYearOfBirth(){ + /** + * Returns the player's year of birth. + * + * @return the player's year of birth + */ + protected int getYearOfBirth() + { return this.yearOfBirth; } + /** + * Returns a string representation of the hockey player, + * which is the player's name. + * + * @return the player's name + */ @Override - public String toString(){ + public String toString() + { return this.name; } } diff --git a/src/code/ca/bcit/comp2522/lab06/HockeyTeam.java b/src/code/ca/bcit/comp2522/lab06/HockeyTeam.java index b711c37..8153a4e 100644 --- a/src/code/ca/bcit/comp2522/lab06/HockeyTeam.java +++ b/src/code/ca/bcit/comp2522/lab06/HockeyTeam.java @@ -1,45 +1,74 @@ package ca.bcit.comp2522.lab06; -import java.util.ArrayList; import java.util.List; /** - * HockeyTeam holds information of a - * hockey team composed by HockeyPlayers and the team's name. + * Represents a hockey team containing a team name and a roster of HockeyPlayer objects. + * + *This class validates input to ensure that a team's name + * is properly initialized and that a valid roster is provided.
* - * @author Braeden Sowinski * @author Nico Agostini + * @author Braeden Sowinski * @author Trishaan Shetty * @author Calvin Arifianto * @version 1.0.0 */ - -public class HockeyTeam { +public class HockeyTeam +{ private final String name; private final ListThis class creates a sample team, performs various operations + * using functional interfaces, and prints the results to the console.
* - * @author Braeden Sowinski * @author Nico Agostini + * @author Braeden Sowinski * @author Trishaan Shetty * @author Calvin Arifianto * @version 1.0.0 */ - -public class Main { - +public class Main +{ + private static final int CURRENT_YEAR = 2025; + private static final int HIGH_SCORE_THRESHOLD = 20; + private static final String FORWARD_POSITION = "F"; + private static final int MIN_AGE = 21; + private static final int MIN_GOALS = 10; + private static final int COUNTER_STARTER = 0; + + /** + * Creates and returns a sample hockey team with several HockeyPlayer objects. + * + * @return a HockeyTeam instance representing a sample team + */ private static HockeyTeam sampleTeam() { final ListThis method showcases examples of Supplier, Predicate, Function, + * Consumer, UnaryOperator, and Comparator applied to HockeyPlayer objects.
+ * + * @param args command-line arguments (not used) + */ + public static void main(final String[] args) + { + final HockeyTeam team; + final List