Question
Driver.java import java.io.*; public class Driver { public static void main(String[] args) throws IOException{ // TODO Auto-generated method stub SpellCheckInterface check = new SpellChecker(); check.loadDictionary(dictionary.txt);
Driver.java import java.io.*; public class Driver { public static void main(String[] args) throws IOException{ // TODO Auto-generated method stub SpellCheckInterface check = new SpellChecker(); check.loadDictionary("dictionary.txt"); if(check.checkDocument("test.txt")) System.out.println("No misspelled words found"); if(check.checkDocument("short.txt")) System.out.println("No misspelled words found"); } }
_______________________________________________
SpellChecker.java
import java.util.*; import java.io.*; public class SpellChecker implements SpellCheckInterface { LinkedListdict; LinkedList misspelled; public SpellChecker() { dict = new LinkedList(); misspelled = new LinkedList (); } /** * Loads the dictionary contained in the specified file * * @param filename The name of the dictionary file to be loaded * @return true If the file was successfully loaded, false * if the file could not be loaded or was invalid * @throws IOException if filename does not exist */ @Override public boolean loadDictionary(String fileName) throws IOException { // Left as exercise return true; } /** * Check the document for misspelled words * * @return A list of misspelled words and * the line numbers where they occur. * @throws @throws IOException if filename does not exist */ @Override public boolean checkDocument(String fileName) throws IOException { misspelled = new LinkedList(); // Initialize for each file int lineNumber = 0; try { File infile = new File(fileName); System.out.println(" File Name:"+ fileName); try ( Scanner in = new Scanner(infile); ) { /* wrong code shold be deleted in.useDelimiter("[^A-Za-z]+"); // split input by words while (in.hasNext()){ String myWord = in.next().toLowerCase(); lineNumber++; */ // Correct code to be added while (in.hasNextLine()){ String line = in.nextLine().toLowerCase(); lineNumber++; String[] tokens = line.split("[ \\P{Alpha}]+"); for(int i=0;i ___________________________________________________
SpellCheckInterface.java
Details
Activity
Last month
Feb 18
B
Bahram Zartoshty shared an item
SpellCheckInterface.java
Can view
You
Feb 5
B
Bahram Zartoshty uploaded an item
SpellCheckInterface.java
No recorded activity before February 5, 2019
All selections cleared
import java.io.*; public interface SpellCheckInterface { /** * Loads the dictionary contained in the specified file * * @param filename The name of the dictionary file to be loaded * @return true If the file was successfully loaded, false * if the file could not be loaded or was invalid * @throws IOException if filename does not exist */ public boolean loadDictionary(String fileName) throws IOException; /** * Check the document for misspelled words * * @return true if the file was successfully spell checked, false * if the file had misspelled words * @throws IllegalArgumentException if filename is null */ public boolean checkDocument(String fileName) throws IOException; }______________________________
Word.java
Details
Activity
Last month
Feb 18
B
Bahram Zartoshty shared an item
Word.java
Can view
You
Feb 5
B
Bahram Zartoshty uploaded an item
Word.java
No recorded activity before February 5, 2019
All selections cleared
import java.util.*; public class Word implements ComparableTranscribed image text{ private String word; private ArrayList lines; public Word() { lines = new ArrayList(); } public Word(String w, int lineNumber) { word = w; lines = new ArrayList(); lines.add(lineNumber); } public String getWord() { return word; } public ArrayList getLines() { return lines; } public void addLine(int lineNumber) { lines.add(lineNumber); } public String toString() { return word + " : "+lines.toString(); } /** *@return true if two words are equal, false otherwise */ @Override public boolean equals(Object w) { // Left as exercise } /** *@ compare two words and retun the corresponding integer value (0) */ @Override public int compareTo(Word w) { return this.word.compareTo(w.word); } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started