Skip to content

Instantly share code, notes, and snippets.

@kenechiokolo
Created April 17, 2015 12:13
Show Gist options
  • Save kenechiokolo/d7415bf3f750a8409903 to your computer and use it in GitHub Desktop.
Save kenechiokolo/d7415bf3f750a8409903 to your computer and use it in GitHub Desktop.
Hangman Lexicon (CS106A Assignment 4)
/*
* File: HangmanLexicon.java
* -------------------------
* This file contains a stub implementation of the HangmanLexicon
* class that you will reimplement for Part III of the assignment.
*/
import java.util.*;
import java.io.*;
public class HangmanLexicon {
public HangmanLexicon() {
createLexiconArray();
}
// reads lexicon from file HangmanLexicon.txt and creates an array containing all the words in the lexicon
private void createLexiconArray() {
try {
BufferedReader rd = new BufferedReader (new FileReader("HangmanLexicon.txt"));
while (true) {
String line = rd.readLine();
if (line == null) break;
hLexicon.add(line);
}
rd.close();
} catch (IOException ex) {
// I really had no idea of what to put here....
}
}
/** Returns the number of words in the lexicon. */
public int getWordCount() {
return hLexicon.size();
}
/** Returns the word at the specified index. */
public String getWord(int index) {
String word = hLexicon.get(index);
return word;
}
ArrayList <String> hLexicon = new ArrayList <String>(); // creates an ArrayList
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment