Advertisement
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.IOException;
- import java.util.Scanner;
- public class SpellChecker {
- private static void process(Scanner sc, String args[]) throws IOException {
- //load dictionary
- Dictionary<String> check = new Dictionary();
- //load txt
- System.out.print("Choose text from file location compsci220/: ");
- String txt="alice30";
- Scanner text = new Scanner(System.in);
- if(txt==text.nextLine()){
- txt=text.nextLine();
- System.out.println("Processing 'Alice in the Wonderland'");
- }
- ScannerWithLineno swl = new ScannerWithLineno(new File("compsci220/"+txt+".txt"));
- while (swl.hasNext()) {
- String word = swl.next();
- //processing file, compare words
- if(check.lookUpWord(word)==false){
- //for each line surround each misspelled word in * *
- System.out.println("line"+swl.getLineno()+": "+swl.getCurrentLine()+"*"+word+"*");
- }
- System.out.println(swl.getLineno() + ": " + swl.getCurrentLine() + " " + word);
- if (swl.getLineno() >= 20)
- break;
- }
- swl.close();
- sc.nextLine(); // IMPORTANT!! Reset Scanner
- }
- //**********************************************
- private static boolean doThisAgain(Scanner sc, String prompt) {
- System.out.print(prompt);
- String doOver = sc.nextLine();
- return doOver.equalsIgnoreCase("Y");
- }
- //**********************************************
- public static void main(String args[]) throws IOException {
- final String TITLE = "CSC111 Project Template";
- final String CONTINUE_PROMPT = "Do this again? [y/N] ";
- System.out.println("Welcome to " + TITLE);
- Scanner sc = new Scanner(System.in);
- do {
- process(sc, args);
- } while (doThisAgain(sc, CONTINUE_PROMPT));
- sc.close();
- System.out.println("Thank you for using " + TITLE);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement