Omar_Natour

Natour, O. Dictionary

Dec 2nd, 2016
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.90 KB | None | 0 0
  1. /*Omar Natour 11/30/16
  2.  * Csc-220 Data Structures
  3.  * Hw8 Spell checker
  4.  * create a program that can check words against a created dictionary class
  5.  */
  6.  
  7. package chapter24;
  8.  
  9. import java.io.File;
  10. import java.io.FileNotFoundException;
  11. import java.util.Scanner;
  12.  
  13. public class Dictionary<E extends String> extends MostRecentlyUsedLinkedList<E> {
  14.  
  15.     public Dictionary() {
  16.     }
  17.  
  18.     public Dictionary(E[] words) {
  19.         super();
  20.     }
  21.  
  22.     @SuppressWarnings("unchecked")
  23.     public void loadDictionary(String filename) {
  24.         try {
  25.  
  26.             Scanner sc = new Scanner(new File("chapter24/" + filename));
  27.  
  28.             while (sc.hasNextLine())
  29.                 this.add((E) sc.nextLine());
  30.             sc.close();
  31.  
  32.         } catch (FileNotFoundException fnfe) {
  33.             System.err.println(fnfe);
  34.         } catch (Exception e) {
  35.             System.err.println(e);
  36.         }
  37.  
  38.     }
  39.  
  40.     public int lookUpWord(E word) {
  41.         return this.indexOf(word);
  42.     }
  43.  
  44. }
Add Comment
Please, Sign In to add comment