diff --git a/src/main/java/uta/cse3310/WordList.java b/src/main/java/uta/cse3310/WordList.java index 4c3f7b2..b8e0f2c 100644 --- a/src/main/java/uta/cse3310/WordList.java +++ b/src/main/java/uta/cse3310/WordList.java @@ -10,50 +10,38 @@ import java.nio.file.Paths; public class WordList { - // Static list to store words read from file public static List list; - // Method to read words from a file and return shuffled word list public static ArrayList getWordList(String wordsFile) { ArrayList wordList = new ArrayList<>(); try { - // Read all lines from the specified file List lines = Files.readAllLines(Paths.get(wordsFile)); - - // If file is empty, print message and return empty list if (lines.isEmpty()) { System.out.println("The file is empty: " + wordsFile); - return wordList; + return wordList; // Return empty list if the file is empty } - // Store lines in a static list and shuffle the words list = new ArrayList<>(lines); shuffleWords(); - - // Add shuffled words to word list wordList.addAll(list); } catch (IOException e) { - // Print error message and stack trace if an exception occurs System.out.println("Error reading the file: " + wordsFile); - e.printStackTrace(); + e.printStackTrace(); // Print the stack trace for debugging } return wordList; } - // Method to shuffle words in the static list public static void shuffleWords() { Collections.shuffle(list); } - // Method to update word list based on character limit public static ArrayList updatedWordList(ArrayList wordBank) { int totalCharacters = 0; int index = 0; ArrayList updatedList = new ArrayList<>(); - // Iterate through word bank and add words until character limit is reached while (totalCharacters < 500 && index < wordBank.size()) { String word = wordBank.get(index); if (totalCharacters + word.length() <= 500) {