Question & Answer: Please help. Beginner Java Programming: My program with Instructions. (arrays, me…..

Please help. Beginner Java Programming: My program with Instructions. (arrays, methods, loops, boolean)

import java.util.Scanner;

public class FinalProgram

{

public static void main(String args[])

{

/*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 <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!”.*/

 

 

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();

int countUnknownWords =0;

if()//if the word isn’t in the dictionary

{

System.out.println(” Unknown word ” + <word> + ” found.”);

}

System.out.println(“The total number of unknown words are : “);

countUnknownWords++;

input.close();

}

public static void isInDictionary(String[] array,String userInput, String userDictionary )

{

 

}

}

Expert Answer

 

/*The source code of the above said program is given below:*/

import java.util.Scanner;

public class FinalProgram

{

public static void main(String args[])

{

/*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 <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!”.*/

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(“nEnter the dictionary string: “);//prompt the user to enter a dictionary string

String dictionaryStr = input.nextLine();

 

String[] inputWords=inputStr.split(“\s”);//splits the input string based on whitespace

String[] dictionaryArray=dictionaryStr.split(“\s”);//splits the dictionary string based on whitespace

int countUnknownWords =0;

/*traversing the entire input string*/

for(int i=0; i<inputWords.length;i++)

{

if(!isInDictionary(dictionaryArray,inputWords[i]))//checking if the word isn’t in the dictionary

{

System.out.println(“n Unknown word <” + inputWords[i] + “> found.”);

countUnknownWords++;

}

else

continue;

}

/*displaying a message describing the total number of misspelled words in the input string*/

System.out.println(“nThe total number of unknown words are : “+countUnknownWords);

input.close();

}

public static boolean isInDictionary(String[] dictionaryArray,String userInput)

{

/*searching the dictionary string for the given word*/

for(int i=0;i<dictionaryArray.length;i++)

{

/*if the word is found returns true */

if(dictionaryArray[i].equalsIgnoreCase(userInput))

return true;

}

/*if the word is not found returns false */

return false;

}

}

/*For better understanding code image and output screenshot is given here:*/

Still stressed from student homework?
Get quality assistance from academic writers!