Created
November 17, 2011 22:50
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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