Advertisement
Guest User

Untitled

a guest
May 27th, 2015
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. /*
  2. * File: HangmanLexicon.java
  3. * -------------------------
  4. * This file contains a stub implementation of the HangmanLexicon
  5. * class that you will reimplement for Part III of the assignment.
  6. */
  7.  
  8. import java.util.*;
  9. import java.io.*;
  10.  
  11. public class HangmanLexicon {
  12.  
  13. public HangmanLexicon() {
  14. createLexiconArray();
  15. }
  16.  
  17. // reads lexicon from file HangmanLexicon.txt and creates an array containing all the words in the lexicon
  18. private void createLexiconArray() {
  19. try {
  20. BufferedReader rd = new BufferedReader (new FileReader("HangmanLexicon.txt"));
  21. while (true) {
  22. String line = rd.readLine();
  23. if (line == null) break;
  24. hLexicon.add(line);
  25. }
  26. rd.close();
  27. } catch (IOException ex) {
  28. // I really had no idea of what to put here....
  29. }
  30. }
  31.  
  32. /** Returns the number of words in the lexicon. */
  33. public int getWordCount() {
  34. return hLexicon.size();
  35. }
  36.  
  37. /** Returns the word at the specified index. */
  38. public String getWord(int index) {
  39. String word = hLexicon.get(index);
  40. return word;
  41. }
  42.  
  43. ArrayList <String> hLexicon = new ArrayList <String>(); // creates an ArrayList
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement