Question

In: Computer Science

Write a spell checking program (java) which uses a dictionary of words (input by the user...

Write a spell checking program (java) 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:

  1. 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 found" to standard output.
  2. After traversing the entire input string, your program should print a message describing the total number of misspelled words in the string.
  3. 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.
  4. Within a string, a word is a white-space delimited string of characters. So the last word in "Hello world!" is "world!".

Solutions

Expert Solution

dictionary.java

import java.io.*;
import java.util.*;

public class dictionary
{
public static void main(String args[]) throws Exception
{
     
  
   String dString;
   String uString;
  
   Scanner input=new Scanner(System.in);
  
   System.out.println("Enter distionary string :");
  
   dString = input.nextLine();
  
   System.out.println("Enter input string :");
  
   uString = input.nextLine();
  
   String[] dict = dString.split(" ");//split dictionay string and save to array fo string
  
   boolean found = false;
  
   //ieterate over dictionary string array
   for (String a : dict)
   {
       //compare and print message accordingly       
       if((uString.toLowerCase().compareTo(a.toLowerCase())) == 0)
       {
   System.out.println("word found!");
           found = true;
           break;
       }
   }
  
   if(found == false)
   {
       System.out.println("Unknown word found!");
   }
  
  
  
}
}


Related Solutions

Write a program that prompts the user to input a string. The program then uses the...
Write a program that prompts the user to input a string. The program then uses the function substr to remove all the vowels from the string. For example, if str=”There”, then after removing all the vowels, str=”Thr”. After removing all the vowels, output the string. Your program must contain a function to remove all the vowels and a function to determine whether a character is a vowel. You must insert the following comments at the beginning of your program and...
Write a Java program that prompts the user to input a string and prints whether it...
Write a Java program that prompts the user to input a string and prints whether it is a palindrome. A palindrome is a string which reads the same backward as forward, such as Madam (disregarding punctuation and the distinction between uppercase and lowercase letters). The program must use the stack data structure. The program must include the following classes: The StackX class (or you can use the Java Stack class). The Palindrome class which must contain a method named palindrome()...
Write a Java program that uses the file EnglishWordList.txt which contains a collection of words in...
Write a Java program that uses the file EnglishWordList.txt which contains a collection of words in English (dictionary), to find the number of misspelled words in a story file called Alcott-little-261.txt. Please note that the dictionary words are all lower-cased and there are no punctuation symbols or numbers. Hence it is important that you eliminate anything other than a-z and A-Z and then lower case story words for valid comparisons against the WordList file. When you read each line of...
Write a Java program that uses the file EnglishWordList.txt which contains a collection of words in...
Write a Java program that uses the file EnglishWordList.txt which contains a collection of words in English (dictionary), to find the number of misspelled words in a story file called Alcott-little-261.txt. Please note that the dictionary words are all lower-cased and there are no punctuation symbols or numbers. Hence it is important that you eliminate anything other than a-z and A-Z and then lower case story words for valid comparisons against the WordList file. When you read each line of...
Write a program in C, that uses standard input and output to ask the user to...
Write a program in C, that uses standard input and output to ask the user to enter a sentence of up to 50 characters, the ask the user for a number between 1 & 10. Count the number of characters in the sentence and multiple the number of characters by the input number and print out the answer. Code so far: char sentence[50]; int count = 0; int c; printf("\nEnter a sentence: "); fgets(sentence, 50, stdin); sscanf(sentence, %s;    for(c=0;...
Write java program that will ask for the user for 2 input lines and print out...
Write java program that will ask for the user for 2 input lines and print out all words that occur 1 or more times on both lines (case sensitive). Write this without arrays and method. Here is a sample run: <Output> Enter two lines to process. The quick brown fox jumps over a lazy dog The fox hound outruns the lazy dog The words that occur on both lines are: The fox lazy dog
User the Scanner class for your input Write a java program to calculate the area of...
User the Scanner class for your input Write a java program to calculate the area of a rectangle. Rectangle Area is calculated by multiplying the length by the width   display the output as follow: Length =   Width = Area = Load: 1. Design (Pseudocode ) 2. Source file (Java file, make sure to include comments) 3. Output file (word or pdf or jpig file)
Write a C++ or Java program that reads an input graph data from a user. Then,...
Write a C++ or Java program that reads an input graph data from a user. Then, it should present a path for the travelling salesman problem (TSP). In the assignment, you can assume that the maximum number ofvertices in the input graph is less than or equal to 20. Input format: This is a sample input from a user. 4 12 0 1 2 0 3 7 0 2 5 1 0 2 1 2 8 1 3 3 2...
Write a Java program that reads an input graph data from a user. Then, it should...
Write a Java program that reads an input graph data from a user. Then, it should present a path for the travelling salesman problem (TSP). In the assignment, you can assume that the maximum number of vertices in the input graph is less than or equal to 20. Input format: This is a sample input from a user. 4 12 0 1 2 0 3 7 0 2 5 1 0 2 1 2 8 1 3 3 2 0...
JAVA Write a program that checks the spelling of words in a document. This program uses...
JAVA Write a program that checks the spelling of words in a document. This program uses two text files: A dictionary file containing all known correctly spelled words, and A document to be spell-checked against the dictionary. As the document to be spell checked is read, each of its words is checked against the dictionary words. The program determines whether each word is misspelled. Misspelled words are recorded. is spelled correctly. Correctly spelled words are recorded and their frequency counted....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT