Question Solved1 Answer Homework - Topic 8 - Word Count: Write a program that reads in and prints a text, line by line, and calls a series of methods as needed. The object of the program is to parse a sentence in order to figure out all the different words that are in the sentence and how many times each word occurs. Use two parallel arrays, one to store the different words (e.g., word[]) and one to store the appearance count for each word (e.g., wordCount[]). At the end, print the list of different words and their counts. (Extra Credit: print the list of words and their counts in alphabetical order.) You have to decide which methods to implement. For example, suppose the text is this: The elephant ate the banana and the giraffe ate the banana. The output would produces this list: 1 and ate banana elephant giraffe the 2 2 1 1 4 Hint: Think Bank Accounts! (Use what you learned in the Bank Accounts program.)

OTHFSS The Asker · Computer Science

Transcribed Image Text: Homework - Topic 8 - Word Count: Write a program that reads in and prints a text, line by line, and calls a series of methods as needed. The object of the program is to parse a sentence in order to figure out all the different words that are in the sentence and how many times each word occurs. Use two parallel arrays, one to store the different words (e.g., word[]) and one to store the appearance count for each word (e.g., wordCount[]). At the end, print the list of different words and their counts. (Extra Credit: print the list of words and their counts in alphabetical order.) You have to decide which methods to implement. For example, suppose the text is this: The elephant ate the banana and the giraffe ate the banana. The output would produces this list: 1 and ate banana elephant giraffe the 2 2 1 1 4 Hint: Think Bank Accounts! (Use what you learned in the Bank Accounts program.)
More
Transcribed Image Text: Homework - Topic 8 - Word Count: Write a program that reads in and prints a text, line by line, and calls a series of methods as needed. The object of the program is to parse a sentence in order to figure out all the different words that are in the sentence and how many times each word occurs. Use two parallel arrays, one to store the different words (e.g., word[]) and one to store the appearance count for each word (e.g., wordCount[]). At the end, print the list of different words and their counts. (Extra Credit: print the list of words and their counts in alphabetical order.) You have to decide which methods to implement. For example, suppose the text is this: The elephant ate the banana and the giraffe ate the banana. The output would produces this list: 1 and ate banana elephant giraffe the 2 2 1 1 4 Hint: Think Bank Accounts! (Use what you learned in the Bank Accounts program.)
See Answer
Add Answer +20 Points
Community Answer
DANO9F The First Answerer
See all the answers with 1 Unlock
Get 4 Free Unlocks by registration

import java.util.*; public class wordCount {     //fucntion to search the word in the list of strings     public static int search(String word[], String temp_word, int k)     {         //iterate over the array of words         for(int i = 0;i < k;i++)         {             //if the word found, return the index             if(word[i].equals(temp_word))             {                 return i;             }         }         //if the word not fount return -1         return -1;     }     //function to sort two parallel arrays     public static void sort(String word[], int wordCount[], int k)     {         //iterate over the array using nested loops         for(int i = 0;i < k - 1;i++)         {             for(int j = 0;j < k - i - 1;j++)             {                 //if the word at lower index is greater than word at higher index                 //swap the two words                 //swap the two word counts                 if(word[j].compareTo(word[j + 1]) > 0)                 {                     String temp1;                     int temp2;                     temp1 = word[j];                     word[j] = word[j + 1];                     word[j + 1] = temp1;                     temp2 = wordCount[j];                     wordCount[j] = wordCount[j + 1];                     wordCount[j + 1] = temp2;                 }             }         }     }     public static void main(String args[])     {         //create scanner object to read data from user         Scanner sc = new Scanner(System.in);         //prompt the user to enter a sentence         System.out.print("Enter a sentence: ");         String input = sc.nextLine();         int k, n, i;         i = 0;         k = 0;         //create two parallel arrays         String word[] = new String[20];         int wordCo ... See the full answer