Browse Source

changed style

master
school 7 years ago
parent
commit
5c1d98c95d
  1. 21
      Dictionary.java

21
Dictionary.java

@ -1,38 +1,31 @@
import java.util.*;
import java.io.*;
public class Dictionary
{
public class Dictionary {
public static final String ALPHABET = "abcdefghijklmnopqrstuvwxyz";
private ArrayList<String> wordList;
public Dictionary()
{
public Dictionary() {
loadWords();
}
public String getRandomWord()
{
public String getRandomWord() {
int idx = (int)(Math.random() * this.wordList.size());
return wordList.get(idx);
}
private void loadWords()
{
private void loadWords() {
this.wordList = new ArrayList<String>();
File f = new File("words.txt");
try
{
try {
Scanner in = new Scanner(f);
while(in.hasNext())
{
while (in.hasNext()) {
String word = in.next();
wordList.add(word);
}
in.close();
}
catch(FileNotFoundException ex)
{
catch (FileNotFoundException ex) {
System.out.println("File not found.");
}
}
Loading…
Cancel
Save