Advertisement
nate23nate23

spellchecker - fucked

Dec 1st, 2016
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.10 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.IOException;
  16. import java.util.Scanner;
  17.  
  18. public class SpellChecker {
  19.  
  20.         private static void process(Scanner sc, String args[]) throws IOException {
  21.             //load dictionary
  22.             Dictionary<String> check = new Dictionary();
  23.             //load txt
  24.             System.out.print("Choose text from file location compsci220/: ");
  25.             String txt="alice30";
  26.             Scanner text = new Scanner(System.in);
  27.             if(txt==text.nextLine()){
  28.             txt=text.nextLine();
  29.             System.out.println("Processing 'Alice in the Wonderland'");
  30.             }
  31.             ScannerWithLineno swl = new ScannerWithLineno(new File("compsci220/"+txt+".txt"));
  32.             while (swl.hasNext()) {
  33.                 String word = swl.next();          
  34.                 //processing file, compare words
  35.                 if(check.lookUpWord(word)==false){
  36.                     //for each line surround each misspelled word in * *
  37.                     System.out.println("line"+swl.getLineno()+": "+swl.getCurrentLine()+"*"+word+"*");
  38.                 }
  39.                 System.out.println(swl.getLineno() + ": " + swl.getCurrentLine() + " " + word);
  40.                 if (swl.getLineno() >= 20)
  41.                     break;
  42.             }
  43.             swl.close();
  44.             sc.nextLine();  // IMPORTANT!! Reset Scanner
  45.         }
  46.        
  47.         //**********************************************
  48.        
  49.         private static boolean doThisAgain(Scanner sc, String prompt) {
  50.             System.out.print(prompt);
  51.             String doOver = sc.nextLine();
  52.             return doOver.equalsIgnoreCase("Y");
  53.         }
  54.        
  55.         //**********************************************
  56.        
  57.         public static void main(String args[]) throws IOException {
  58.             final String TITLE = "CSC111 Project Template";
  59.             final String CONTINUE_PROMPT = "Do this again? [y/N] ";
  60.            
  61.             System.out.println("Welcome to " + TITLE);
  62.             Scanner sc = new Scanner(System.in);
  63.             do {
  64.                 process(sc, args);
  65.             } while (doThisAgain(sc, CONTINUE_PROMPT));
  66.             sc.close();
  67.             System.out.println("Thank you for using " + TITLE);
  68.         }
  69.  
  70.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement