diff --git a/HockeyStats.java b/HockeyStats.java index 47512bd..e76d748 100644 --- a/HockeyStats.java +++ b/HockeyStats.java @@ -1,3 +1,11 @@ +/** + * HockeyStats.java + * + *

The main driver class for the Hockey Stats Manager. Handles user input, file I/O operations, + * and menu navigation. + * + * @author Cody Trainer + */ import java.io.*; import java.util.*; @@ -7,14 +15,25 @@ public class HockeyStats { static StringTokenizer st; static Scanner s = new Scanner(System.in); + /** + * Runs the primary menu loop. + * + * @param args Command line arguments (not used). + * @throws Exception If file reading or input errors occur. + */ public static void main(String[] args) throws Exception { - while (true) { if (showMenu()) break; } s.close(); } + /** + * Loads player data from a specified text file. + * + * @param fileName The name of the file to load from. + * @throws Exception If the file is not found or is improperly formatted. + */ public static void loadData(String fileName) throws Exception { players.clear(); File f = new File(fileName); @@ -34,6 +53,12 @@ public class HockeyStats { br.close(); } + /** + * Saves current player list data to a specified text file. + * + * @param fileName The name of the file to save to. + * @throws Exception If an I/O error occurs. + */ public static void saveData(String fileName) throws Exception { FileWriter fw = new FileWriter(fileName); String save = players.createSaveData(); @@ -42,6 +67,12 @@ public class HockeyStats { System.out.println("Data saved to " + fileName); } + /** + * Displays the main menu and routes user to various sub-menus or actions. + * + * @return true if the user chooses to quit, false otherwise. + * @throws Exception If input errors occur. + */ public static boolean showMenu() throws Exception { System.out.print( """ @@ -95,6 +126,12 @@ public class HockeyStats { return close; } + /** + * Displays the editor menu for adding, removing, or updating player data. + * + * @return true if the user chooses to return to the main menu, false otherwise. + * @throws Exception If input errors occur. + */ public static boolean showDataMenu() throws Exception { System.out.print( """ @@ -176,6 +213,11 @@ public class HockeyStats { return dataExit; } + /** + * Displays the viewer menu for printing, finding, and sorting player statistics. + * + * @return true if the user chooses to return to the main menu, false otherwise. + */ public static boolean showStatsMenu() { System.out.print( """ diff --git a/PlayerList.java b/PlayerList.java index e696b1a..6750bdc 100644 --- a/PlayerList.java +++ b/PlayerList.java @@ -1,25 +1,51 @@ +/** + * PlayerList.java + * + *

Manages a collection of HockeyPlayer objects. Provides functionality for adding, removing, + * searching, and sorting players, as well as generating data for storage. + * + * @author Cody Trainer + */ import java.util.ArrayList; public class PlayerList { ArrayList pList; + /** Constructs an empty PlayerList. */ public PlayerList() { pList = new ArrayList<>(); } + /** Removes all players from the list. */ public void clear() { pList.clear(); } + /** + * Adds a HockeyPlayer to the list. + * + * @param p The HockeyPlayer object to add. + */ public void addPlayer(HockeyPlayer p) { pList.add(p); } + /** + * Removes a player from the list by their name. + * + * @param name The name of the player to remove. + * @return true if the player was found and removed, false otherwise. + */ public boolean removePlayer(String name) { HockeyPlayer p = findPlayer(name); return pList.remove(p); } + /** + * Returns a concatenated string of all players' detailed statistics. + * + * @return A multi-line string containing all player stats. + */ public String toString() { String s = ""; for (HockeyPlayer p : pList) { @@ -28,6 +54,12 @@ public class PlayerList { return s; } + /** + * Creates a raw data string formatted for file output. The format includes the list size followed + * by individual player data. + * + * @return A string representation of the list for saving to a file. + */ public String createSaveData() { String s = pList.size() + "\n"; for (HockeyPlayer p : pList) { @@ -36,6 +68,12 @@ public class PlayerList { return s; } + /** + * Searches for a player in the list by name. + * + * @param name The name of the player to find. + * @return The HockeyPlayer object if found, null otherwise. + */ public HockeyPlayer findPlayer(String name) { HockeyPlayer newPlayer = new HockeyPlayer(name); for (HockeyPlayer p : pList) { @@ -44,6 +82,12 @@ public class PlayerList { return null; } + /** + * Filters the list to find players who have scored more than a specific number of goals. + * + * @param num The goal threshold. + * @return A new PlayerList containing only players above the threshold. + */ public PlayerList getPlayersGoalsAbove(int num) { PlayerList newList = new PlayerList(); for (HockeyPlayer p : pList) { @@ -54,6 +98,7 @@ public class PlayerList { return newList; } + /** Sorts the players in the list alphabetically by name using a Bubble Sort algorithm. */ public void sortByNames() { for (int i = 0; i < pList.size(); i++) { boolean swapped = false; @@ -69,8 +114,7 @@ public class PlayerList { } } - // if (pList.get(i).getPoints() > pList.get(j).getPoints()) { - + /** Sorts the players in the list by total points using a Selection Sort algorithm. */ public void sortByPoints() { for (int i = 0; i < pList.size(); i++) { int minInd = i; @@ -85,6 +129,15 @@ public class PlayerList { } } + /** + * Locates a player and updates their stats with results from a single game. + * + * @param name The name of the player. + * @param goals Goals scored in the game. + * @param assists Assists made in the game. + * @param gameWon Whether the game was won. + * @return The updated HockeyPlayer object, or null if the player doesn't exist. + */ public HockeyPlayer addGameToPlayer(String name, int goals, int assists, boolean gameWon) { HockeyPlayer p = findPlayer(name); if (p == null) return null;