nate23nate23

dictionary - done

Dec 1st, 2016
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.68 KB | None | 0 0
  1. /*
  2.      * Name:Nate Wheeler
  3.      * Date:november 18, 2016
  4.      * Course Number: csc220
  5.      * Course Name: data structures
  6.      * Problem Number: hw08
  7.      * Email: nate23nate23@gmail.com
  8.      * Short Description of the Problem
  9.      * make spell-checker using a dictionary
  10.      */
  11.  
  12. package compsci220;
  13.  
  14. import java.io.File;
  15. import java.io.FileInputStream;
  16. import java.io.IOException;
  17. import java.net.URL;
  18. import java.util.Iterator;
  19. import java.util.Scanner;
  20.  
  21. public class Dictionary<E> extends MyLinkedList<String>{
  22.    
  23.     private MyLinkedList<String> list;
  24.    
  25.     public Dictionary() throws IOException{
  26.         list = loadDictionary(new File("compsci220/words2.txt"));
  27.        
  28.     }
  29.     public MyLinkedList<String> loadDictionary(File c)throws IOException{
  30.         String word;
  31.         try {
  32.              Scanner sc = new Scanner(new FileInputStream(c));
  33.              while (sc.hasNextLine()){
  34.              word = sc.nextLine();
  35.              list.add(word);
  36.              }
  37.              sc.close();
  38.              }
  39.              catch (Exception e) {
  40.              e.printStackTrace();
  41.              System.out.println("There was a problem. mostly likely not the file");
  42.              }
  43.         return list;
  44.              
  45.     }
  46. //  public MyLinkedList<String> loadDictionary(URL u)throws IOException{
  47. //      String word;
  48. //      try {
  49. //           Scanner sc = new Scanner(new u.openStream());
  50. //           while (sc.hasNextLine()){
  51. //           word = sc.nextLine();
  52. //           list.add(word);
  53. //           }
  54. //           sc.close();
  55. //           }
  56. //           catch (Exception e) {
  57. //           e.printStackTrace();
  58. //           System.out.println("There was a problem with the file.");
  59. //           }
  60. //      return list;
  61. //           
  62. //  }
  63.     public boolean lookUpWord(E e){
  64.         Iterator<String> listrun= list.iterator();
  65.         while(listrun.hasNext()){
  66.             if(listrun.equals(e))
  67.                 return true;
  68.         }
  69.         return false;
  70.        
  71.     }
  72.  
  73. }
Add Comment
Please, Sign In to add comment