Question Solved1 Answer *******PLEASE DO NOT COPY AND PASTE THIS PROGRAM,PLEASE MAKE IT ORIGINAL*******THIS PROGRAM IS TO BE COMPLETED INJAVA 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., String[] word) and one to store the appearance count for each word (e.g., int[] 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: and ate banana elephant giraffe the 1 2 2 1 1 4 Hint: Think Bank Accounts! (Use what you learned in the Bank Accounts program.) Required Submission: 1. The Java source code file (e.g., HW8.java) 2. The data input file containing the sentence to be parsed (e.g., input.txt) 3. The program generated output file (e.g., output.txt)

AUY3Y5 The Asker · Computer Science

*******PLEASE DO NOT COPY AND PASTE THIS PROGRAM, PLEASE MAKE IT ORIGINAL*******

THIS PROGRAM IS TO BE COMPLETED IN JAVA

Transcribed Image Text: 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., String[] word) and one to store the appearance count for each word (e.g., int[] 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: and ate banana elephant giraffe the 1 2 2 1 1 4 Hint: Think Bank Accounts! (Use what you learned in the Bank Accounts program.) Required Submission: 1. The Java source code file (e.g., HW8.java) 2. The data input file containing the sentence to be parsed (e.g., input.txt) 3. The program generated output file (e.g., output.txt)
More
Transcribed Image Text: 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., String[] word) and one to store the appearance count for each word (e.g., int[] 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: and ate banana elephant giraffe the 1 2 2 1 1 4 Hint: Think Bank Accounts! (Use what you learned in the Bank Accounts program.) Required Submission: 1. The Java source code file (e.g., HW8.java) 2. The data input file containing the sentence to be parsed (e.g., input.txt) 3. The program generated output file (e.g., output.txt)
See Answer
Add Answer +20 Points
Community Answer
HQAJBP The First Answerer
See all the answers with 1 Unlock
Get 4 Free Unlocks by registration

Here is the answer for your question in Java Programming Language. NOTE : Since it is mentioned in the question to read a sentence, I kept the sample single line sentence given in question in 'input.txt' file.  CODE :  import java.io.BufferedWriter; import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.util.Scanner; public class WordCount {              public static void main(String[] args) throws IOException{                 //Let the input file name be 'input.txt' (Read the file name from the user if you want to read from another file)         String fileName = "input.txt";                  //File object and scanner objects         File file = new File(fileName);         Scanner reader = new Scanner(file);                  //Assuming only one line in the text file         //Reading the text and storing it in the 'line' variable         String line = reader.nextLine();         //Splitting the line to words         String[] words = line.split(" |\\.");                  //Close the reader object         reader.close();;         //Array to hold appearance counts         int[] appearanceCount = new int[words.length];                  //Calling UniqueWords Methods to store all unique words of line in an arra         String[] uniqueWords = UniqueWords(words);                  //Calling AppearanceCount method to get appearance count of each word uniqueWords.         appearanceCount = AppearanceCount(uniqueWords,words);                  //Sorting the arrays in alpbhabetical order         SortArrays(uniqueWords,appearanceCount);                  //Writing output to a file         PrintArrays(uniqueWords,appearanceCount);                       }          //Implementation of UniqueWords     public static String[] UniqueWords(String[] words){                 //Create an array to store unique words         String[] uniqueWords = new String[words.length];         //Flag to check whether the word is already exists or not         boolean flag;         int k = 0;         //Loop through each word in 'words'         for(String word : words){             flag = false;             //Loop length of uniqueWords times             for(int i = 0;i<k;i++){                 //If the word is already exists                 if(uniqueWords[i].equalsIgnoreCase(word)){                    flag = true;                 }             }             //If flag is still false             if(flag == false){                 //Add the word to array                 uniqueWords[k] = word;                 //Increment k by 1                 k++;             }                     }         String[] resizedUniqueWords = new String[k];         for(int i =0;i<k;i++)             resizedUniqueWords[i] = uniqueWords[i];         //Return uniqueWords array         return resizedUniqueWords;     }   &#1 ... See the full answer