Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * 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
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement