Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
muktar1907 committed May 2, 2024
2 parents d7e9636 + 63fd875 commit b340999
Showing 1 changed file with 2 additions and 14 deletions.
16 changes: 2 additions & 14 deletions src/main/java/uta/cse3310/WordList.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,50 +10,38 @@
import java.nio.file.Paths;

public class WordList {
// Static list to store words read from file
public static List<String> list;

// Method to read words from a file and return shuffled word list
public static ArrayList<String> getWordList(String wordsFile) {
ArrayList<String> wordList = new ArrayList<>();

try {
// Read all lines from the specified file
List<String> 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<String> updatedWordList(ArrayList<String> wordBank) {
int totalCharacters = 0;
int index = 0;
ArrayList<String> 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) {
Expand Down

0 comments on commit b340999

Please sign in to comment.