diff --git a/Dictionary.java b/Dictionary.java index be577d7..4004fe0 100755 --- a/Dictionary.java +++ b/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 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(); 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."); } }