Skip to content

Instantly share code, notes, and snippets.

@NatashaTheRobot
Created November 17, 2011 22:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NatashaTheRobot/1374818 to your computer and use it in GitHub Desktop.
Save NatashaTheRobot/1374818 to your computer and use it in GitHub Desktop.
This is the solution for part 3 of the Stanford CS106A Hangman Game, the HangmanLexicon Solution
/*
* File: HangmanLexicon.java
* -------------------------
* This file contains a stub implementation of the HangmanLexicon
* class that you will reimplement for Part III of the assignment.
*/
import acm.util.*;
import java.io.*;
import java.util.*;
public class HangmanLexicon {
private ArrayList <String> wordList = new ArrayList <String> ();
public HangmanLexicon() {
//adds the individual words in the file to the array list
try {
BufferedReader hangmanWords = new BufferedReader(new FileReader("HangmanLexicon.txt"));
while(true) {
String line = hangmanWords.readLine();
if(line == null) break;
wordList.add(line);
}
hangmanWords.close();
} catch (IOException ex) {
throw new ErrorException(ex);
}
}
/** Returns the word at the specified index. */
public String getWord(int index) {
return wordList.get(index);
}
/** Returns the number of words in the lexicon. */
public int getWordCount() {
return wordList.size();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment