Question: Please check my program to make sure I'm not missing anything. Thank you! Write a spell checking program which uses a dictionary of words (input
Please check my program to make sure I'm not missing anything. Thank you!
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 the input string and the dictionary string. A valid dictionary string contains an alphabetized list of words.
Functional requirements:
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 the message "Unknown word
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!".
My program
import java.util.Scanner;
public class FinalProgram
{
public static void main(String args[])
{
Scanner input = new Scanner(System.in);
System.out.print("Enter the input string : ");//prompt user to enter a input string
String inputStr = input.nextLine();
System.out.print("Enter the dictionary string: ");//prompt the user to enter a dictionary string
String dictionaryStr = input.nextLine();
String[] usersInputString=inputStr.split(" ");//splits the input string based on whitespace
String[] usersDictionaryArray=dictionaryStr.split(" ");//splits the dictionary string based on whitespace
int countUnknownWords =0;
for(int i=0; i { if(!isInDictionary(usersDictionaryArray,usersInputString[i]))//checking if the word isn't in the dictionary { System.out.println("Unknown word \" " + usersInputString[i] + " \" found."); countUnknownWords++; } else { continue; } } System.out.println("There are a total of " + countUnknownWords + " unknown words. ");//the total number of misspelled words in the input string input.close(); } public static boolean isInDictionary(String[] userDictionaryArray,String userInput) { for(int i=0;i { if(userDictionaryArray[i].equalsIgnoreCase(userInput))//if the word is found return true regardless Of case { return true;//if the word is found return true } } return false;//otherwise return false } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
