Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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.javaimage text in transcribed

import java.util.*; import java.io.*; public class SpellChecker implements SpellCheckInterface { LinkedList dict; 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

image text in transcribed

SpellCheckInterface.java

image text in transcribed

Can view

You

Feb 5

B

Bahram Zartoshty uploaded an item

image text in transcribed

SpellCheckInterface.java

No recorded activity before February 5, 2019

All selections cleared

image text in transcribed

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

image text in transcribed

Word.java

image text in transcribed

Can view

You

Feb 5

B

Bahram Zartoshty uploaded an item

image text in transcribed

Word.java

No recorded activity before February 5, 2019

All selections cleared

image text in transcribed

import java.util.*; public class Word implements Comparable { 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); } }
Transcribed image text

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

MySQL Crash Course A Hands On Introduction To Database Development

Authors: Rick Silva

1st Edition

1718503008, 978-1718503007

More Books

Students also viewed these Databases questions

Question

Explain what is meant by the terms unitarism and pluralism.

Answered: 1 week ago