Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a spell checking program which uses a dictionary of words (input by the user as a string) to find misspelled words in a second

Write a spell checking program which uses a dictionary of words (input by the user as a string) to find misspelled words in a second string, the test string. Your program should prompt the user for two strings: first, the test string ("All dogs hate cats") then the dictionary string ("a the and or dog dogs cat cats he she him her"). A valid dictionary string contains a list of words separated by spaces. Your program will then print misspelled word ("All, hate There were two misspelled words.") as a comma separated list. A word is misspelled if it appears in the test string, but not in the dictionary string.

For each word in the input string, your program should search the dictionary string for the given word. If the word is not in the dictionary, you program should print ", " then word, except that the first word is not preceded by a comma.

After traversing the entire input string, your program should print a message describing the total number of misspelled words in the string.

A dictionary string may contain words in uppercase, lowercase, or a mixture of both. The test string may also combine upper and lower case letters. You program should recognize words regardless of case. So if "dog" is in the dictionary string, the word "dOG" should be recognized as a valid word. Similarly, if "CaT" is in the dictionary string, the word "cat" she be recognized as a valid word.

Within a string, a word is a white-space delimited string of characters. So the last word in "Hello world!" is "world!".

Your program is not responsible for recognizing plurals or punctuation as special cases. So if the test string is "cats cat!" and the dictionary string is "cat", your program would output "cats, cat! 2 words are misspelled."

To break to source string into words, you can set up a Scanner to read from that string, rather than the keyboard. String s = "one two three four"; Scanner reading = new Scanner(s); Now calls to reading.next() will return each word in turn.

Nonfunctional requirements

You must implement and use a method,

boolean findWord(String word, String dictionary)

which returns true if the given word matches a word in the dictionary, ignoring case, false otherwise. If the string word begins or ends with whitespace characters (space, tab endline) they should be stripped before searching for the word in the dictionary. You should use the trim method of the String class to do this.

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

Put Your Data To Work 52 Tips And Techniques For Effectively Managing Your Database

Authors: Wes Trochlil

1st Edition

0880343079, 978-0880343077

More Books

Students also viewed these Databases questions

Question

What is management growth? What are its factors

Answered: 1 week ago

Question

What does Processing of an OLAP Cube accomplish?

Answered: 1 week ago