-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWordBank.java
More file actions
28 lines (24 loc) · 798 Bytes
/
Copy pathWordBank.java
File metadata and controls
28 lines (24 loc) · 798 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import java.io.*;
import java.util.*;
public class WordBank {
private ArrayList<String> words = new ArrayList<>();
public void loadWords(String filename) {
try {
BufferedReader reader = new BufferedReader(new FileReader(filename));
String word;
while ((word = reader.readLine()) != null) {
words.add(word.trim().toLowerCase());
}
reader.close();
} catch (IOException e) {
System.out.println("Could not load words from file");
}
}
public String getRandomWord() {
Random random = new Random();
return words.get(random.nextInt(words.size()));
}
public boolean isValidWord(String word) {
return words.contains(word.toLowerCase());
}
}