From 91a0b50434294474a19b1bd1950e88489f4403f9 Mon Sep 17 00:00:00 2001 From: antmorales1 <122925857+antmorales1@users.noreply.github.com> Date: Thu, 2 May 2024 04:44:14 +0000 Subject: [PATCH 1/2] update word list --- src/main/java/uta/cse3310/WordList.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/main/java/uta/cse3310/WordList.java b/src/main/java/uta/cse3310/WordList.java index aa14221..6c16e06 100644 --- a/src/main/java/uta/cse3310/WordList.java +++ b/src/main/java/uta/cse3310/WordList.java @@ -44,6 +44,7 @@ public static ArrayList getWordList(String wordsFile) { // Method to shuffle words in the static list public static void shuffleWords() { + // Shuffling the list to randomize word order Collections.shuffle(list); } @@ -67,3 +68,20 @@ public static ArrayList updatedWordList(ArrayList wordBank) { return updatedList; } + + // Method to remove duplicate words from the list + public static void removeDuplicates() { + // Create a temporary list to store unique words + List uniqueWords = new ArrayList<>(); + + // Iterate through the list and add unique words to temporary list + for (String word : list) { + if (!uniqueWords.contains(word)) { + uniqueWords.add(word); + } + } + + // Replace the original list with the list of unique words + list = uniqueWords; + } +} \ No newline at end of file From 5309c4587b502158d024ce96a42f44f4dd0d9ed9 Mon Sep 17 00:00:00 2001 From: antmorales1 <122925857+antmorales1@users.noreply.github.com> Date: Thu, 2 May 2024 04:45:23 +0000 Subject: [PATCH 2/2] fixed errrors --- src/main/java/uta/cse3310/WordList.java | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/src/main/java/uta/cse3310/WordList.java b/src/main/java/uta/cse3310/WordList.java index aa14221..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) { @@ -67,3 +55,4 @@ public static ArrayList updatedWordList(ArrayList wordBank) { return updatedList; } +} \ No newline at end of file