Omar_Natour

Natour, O. Spellchecker main

Dec 2nd, 2016
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.02 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.  
  13. public class SpellCheck {
  14.  
  15.     static Dictionary English = new Dictionary();
  16.  
  17.     public static void main(String[] args) {
  18.  
  19.         English.loadDictionary("words2.txt");
  20.  
  21.         System.out.println(performCheck("sometext.txt"));
  22.  
  23.     }
  24.  
  25.     public static String performCheck(String filename) {
  26.         String output = "";
  27.  
  28.         try {
  29.  
  30.             ScannerWithLineno sc = new ScannerWithLineno(new File("chapter24/sometext.txt"));
  31.  
  32.             while (sc.hasNext()) {
  33.                 String current = sc.next();
  34.  
  35.                 if (!English.contains(current))
  36.                     output += "*" + current + "* ";
  37.                 else
  38.                     output += current + " ";
  39.  
  40.             }
  41.  
  42.             sc.close();
  43.  
  44.         } catch (FileNotFoundException fnfe) {
  45.             System.err.println(fnfe);
  46.         } catch (Exception e) {
  47.             System.err.println(e);
  48.         }
  49.  
  50.         return output;
  51.     }
  52.  
  53. }
Add Comment
Please, Sign In to add comment