You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
799 B

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