Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Name:Nate Wheeler
- * Date:november 18, 2016
- * Course Number: csc220
- * Course Name: data structures
- * Problem Number: hw08
- * Email: nate23nate23@gmail.com
- * Short Description of the Problem
- * make spell-checker using a dictionary
- */
- package compsci220;
- import java.io.File;
- import java.io.FileInputStream;
- import java.io.IOException;
- import java.net.URL;
- import java.util.Iterator;
- import java.util.Scanner;
- public class Dictionary<E> extends MyLinkedList<String>{
- private MyLinkedList<String> list;
- public Dictionary() throws IOException{
- list = loadDictionary(new File("compsci220/words2.txt"));
- }
- public MyLinkedList<String> loadDictionary(File c)throws IOException{
- String word;
- try {
- Scanner sc = new Scanner(new FileInputStream(c));
- while (sc.hasNextLine()){
- word = sc.nextLine();
- list.add(word);
- }
- sc.close();
- }
- catch (Exception e) {
- e.printStackTrace();
- System.out.println("There was a problem. mostly likely not the file");
- }
- return list;
- }
- // public MyLinkedList<String> loadDictionary(URL u)throws IOException{
- // String word;
- // try {
- // Scanner sc = new Scanner(new u.openStream());
- // while (sc.hasNextLine()){
- // word = sc.nextLine();
- // list.add(word);
- // }
- // sc.close();
- // }
- // catch (Exception e) {
- // e.printStackTrace();
- // System.out.println("There was a problem with the file.");
- // }
- // return list;
- //
- // }
- public boolean lookUpWord(E e){
- Iterator<String> listrun= list.iterator();
- while(listrun.hasNext()){
- if(listrun.equals(e))
- return true;
- }
- return false;
- }
- }
Add Comment
Please, Sign In to add comment