Question

In this lab you will write a spell check program. The program has two input files: one is the dictionary (a list of valid words) and the other is the input file to be spell checked. The program will read in the words for the dictionary, then will read the input file and check whether each word is found in the dictionary. If not, the user will be prompted to leave the word as is, add the word to the dictionary or type in a replacement word and add the replacement word to the dictionary if it is not currently contained in the dictionary Dictionary The Dictionary will have a field to hold the words; the type of this field will be an ArrayList of Strings. Create the following interface and use it when implementing the Dictionary class. public interface DictionaryInterface t void addword (String word); //adds a new word to this dictionary boolean isWord (String word); //returns true if word is in the dictionary and false otherwise int getSize); String toString //number of words in the dictionary //return String of dictionary words The toString) method should return a String with each word on a separate line. Create a constructor with one parameter, a Scanner object which points to the file containing the words for the dictionary. The constructor will read the words, and store them in the Dictionary. Remember there is one word on each line of the dictionary file.

  1. Dictionary.java
  2. DictionaryInterface.java
  3. Spell.java
  4. SpellCheck.java
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Thanks for posting the question, we are glad to help you. Here is the Dictionary.java class that implements the given interface. Questions doesn't state much about Spell.java and SpellCheck.java classes, please share the details and i'll be happy to assist you in that.

Here is the implemented Dictionary.java class

_______________________________________________________________________________________________

import java.util.ArrayList;
import java.util.Scanner;

public class Dictionary implements DictionaryInterface {

    private ArrayList<String> words;

    public Dictionary(Scanner scanner) {
        words = new ArrayList<>(100);
        while(scanner.hasNextLine()){
            words.add(scanner.nextLine().trim().toLowerCase());
        }
    }

    @Override
    public void addWord(String word) {
        if (!words.contains(word.toLowerCase())) {
            words.add(word.toLowerCase());
        }
    }

    @Override
    public boolean isWord(String word) {
        return words.contains(word.toLowerCase());
    }

    @Override
    public int getSize() {
        return words.size();
    }

@Override
public String toString() {
    StringBuilder builder = new StringBuilder();
    for(String word:words){
        builder.append(word).append(" ");
    }
    return builder.toString();
}
}

______________________________________________________________________________________________

Add a comment
Know the answer?
Add Answer to:
Dictionary.java DictionaryInterface.java Spell.java SpellCheck.java In this lab you will write a spell check program. The program...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • In this lab you will write a spell check program. The program has two input files:...

    In this lab you will write a spell check program. The program has two input files: one is the dictionary (a list of valid words) and the other is the document to be spellchecked. The program will read in the words for the dictionary, then will read the document and check whether each word is found in the dictionary. If not, the user will be prompted to leave the word as is or type in a replacement word and add...

  • CSC110 Lab 6 (ALL CODING IN JAVA) Problem: A text file contains a paragraph. You are to read the contents of the file, store the UNIQUEwords and count the occurrences of each unique word. When the fil...

    CSC110 Lab 6 (ALL CODING IN JAVA) Problem: A text file contains a paragraph. You are to read the contents of the file, store the UNIQUEwords and count the occurrences of each unique word. When the file is completely read, write the words and the number of occurrences to a text file. The output should be the words in ALPHABETICAL order along with the number of times they occur and the number of syllables. Then write the following statistics to...

  • Write a Python equivalent program for the Unix spell utility. You can use the dictionary at /usr/...

    Write a Python equivalent program for the Unix spell utility. You can use the dictionary at /usr/share/dict/words (if you machine does not have it, you can copy it from a Linux machine such as npu29). The minimum requirement is to check if each word in the file exists in the dictionary as is (case insensitive). Your spell checker should inlcude at least two features: 1. Check the simple plural forms (add s or es). 2. Check the simple verb past...

  • Write a spell checker that stores a set of words, W, in a hash table and...

    Write a spell checker that stores a set of words, W, in a hash table and implements a function, spellCheck(s), which performs a spell check on the string s with respect to the set of words, W. If s is in W, then the call to spellCheck(s) returns an iterable collection that contains only s, because it is assumed to be spelled correctly in this case. Otherwise, if s is not in W, then the call to spellCheck(s) returns a...

  • Write a program IN PYTHON that checks the spelling of all words in a file. It...

    Write a program IN PYTHON that checks the spelling of all words in a file. It should read each word of a file and check whether it is contained in a word list. A word list available below, called words.txt. The program should print out all words that it cannot find in the word list. Requirements Your program should implement the follow functions: main() The main function should prompt the user for a path to the dictionary file and a...

  • For this week's lab, you will use two of the classes in the Java Collection Framework:...

    For this week's lab, you will use two of the classes in the Java Collection Framework: HashSet and TreeSet. You will use these classes to implement a spell checker. Set Methods For this lab, you will need to use some of the methods that are defined in the Set interface. Recall that if set is a Set, then the following methods are defined: set.size() -- Returns the number of items in the set. set.add(item) -- Adds the item to the...

  • Write a program that employs the four letter word dictionary to check the spelling of an...

    Write a program that employs the four letter word dictionary to check the spelling of an input word (test word). You will need to save the dictionary file to a folder on your computer. For this program you will prompt the user to enter a four letter word (or four characters). Then using a loop read each word from the dictionary and compare it to the input test word. If there is a match then you have spellchecked the word....

  • Write a Java program in Eclipse that reads from a file, does some clean up, and...

    Write a Java program in Eclipse that reads from a file, does some clean up, and then writes the “cleaned” data to an output file. Create a class called FoodItem. This class should have the following: A field for the item’s description. A field for the item’s price. A field for the item’s expiration date. A constructor to initialize the item’s fields to specified values. Getters (Accessors) for each field. This class should implement the Comparable interface so that food...

  • For this week's lab, you will use two of the classes in the Java Collection Framework:...

    For this week's lab, you will use two of the classes in the Java Collection Framework: HashSet and TreeSet. You will use these classes to implement a spell checker. Set Methods For this lab, you will need to use some of the methods that are defined in the Set interface. Recall that if set is a Set, then the following methods are defined: set.size() -- Returns the number of items in the set. set.add(item) -- Adds the item to the...

  • Python 3.7 Coding assignment This Program should first tell users that this is a word analysis...

    Python 3.7 Coding assignment This Program should first tell users that this is a word analysis software. For any user-given text file, the program will read, analyze, and write each word with the line numbers where the word is found in an output file. A word may appear in multiple lines. A word shows more than once at a line, the line number will be only recorded one time. Ask a user to enter the name of a text file....

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT