Omar_Natour

Natour, O. Dictionary

Dec 2nd, 2016
88
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.  * ojnatour0001@student.stcc.edu
  6.  */
  7.  
  8. package chapter24;
  9.  
  10. import java.io.File;
  11. import java.io.FileNotFoundException;
  12. import java.util.Scanner;
  13.  
  14. public class Dictionary<E extends String> extends MostRecentlyUsedLinkedList<E> {
  15.  
  16.     public Dictionary() {
  17.     }
  18.  
  19.     public Dictionary(E[] words) {
  20.         super();
  21.     }
  22.  
  23.     @SuppressWarnings("unchecked")
  24.     public void loadDictionary(String filename) {
  25.         try {
  26.  
  27.             Scanner sc = new Scanner(new File("chapter24/" + filename));
  28.  
  29.             while (sc.hasNextLine())
  30.                 this.add((E) sc.nextLine());
  31.             sc.close();
  32.  
  33.         } catch (FileNotFoundException fnfe) {
  34.             System.err.println(fnfe);
  35.         } catch (Exception e) {
  36.             System.err.println(e);
  37.         }
  38.  
  39.     }
  40.  
  41.     public int lookUpWord(E word) {
  42.         return this.indexOf(word);
  43.     }
  44.  
  45. }
Add Comment
Please, Sign In to add comment