import java.io.File; import java.io.FileNotFoundException; import java.util.ArrayList; import java.util.Scanner; public class FindWords { static ArrayList dictionary = new ArrayList (); //holds all the words in the dictionary text file public static void main(String[] args) { Scanner s = new Scanner(System.in); dictionary = buildDictionary(); //builds an ArrayList of English words using a dictionary text file int misses =0; int points = 0; while(misses < 3) { System.out.println("Enter a word"); String guess = s.nextLine();//Gets a String from the user if(isFound(guess)) //if found in the ArrayList, true is returned and the word is removed from the ArrayList { System.out.println("Good."); //They get as points as letters in the word they guess. } else { System.out.println("Nope. Not a valid word"); misses++; } } System.out.println("Game over. You scored " + points + " points."); } public static ArrayList buildDictionary() { ArrayList wordList = new ArrayList(); File f = new File("dictionary.txt"); Scanner input = null; try //try...catch is used when the possibility of an error could result and we want to catch it without causing a runtime error { input = new Scanner(f); //Scanner is build based on input from the text, not the console } catch (FileNotFoundException e) { e.printStackTrace(); } while (input.hasNext()) { String word = input.nextLine(); //one word appears on each line in the text file wordList.add(word); //add each word into the wordList ArrayList } input.close(); System.out.println(wordList.size() + " words loaded."); //outputs the size of the ArrayList built return wordList; } public static boolean isFound(String g) { return true; } }