Question: (JAVA) Problem 1 and 2: WordFrequencyCounter Knowing how often a word appears in a sentence or block of text is helpful for creating word clouds

(JAVA) Problem 1 and 2: WordFrequencyCounter

Knowing how often a word appears in a sentence or block of text is helpful for creating word clouds and other types of word analysis. And it's more useful when running it against lots of text.

Implement a class WordFrequencyCounter that reads in a file and counts the frequency of words in the file. Then construct a frequency graph (histogram) displaying the words and the frequency, using asterisks to represent each occurrence of the word.

Use this template: WordFrequencyCounter.javaDownload WordFrequencyCounter.java

You must catch any FileNotFoundException that is thrown and print out a message in the format: "File: [filename] not found", e.g., File: words.txt not found

Example:

WordFrequencyCounter counter1 = new WordFrequencyCounter("res/words1.txt"); counter1.getFrequencyGraph(); // the above returns: robert: ****** java: *** fun: ** is: ** agrees: * so: * that: * WordFrequencyCounter.java: /** * Counts the frequencies of words in a file and generates a frequency graph */ public class WordFrequencyCounter { // ADD YOUR INSTANCE VARIABLES HERE /** * Constructor * * @param fileName name of file from which to count word frequencies */ public WordFrequencyCounter(String fileName) { // FILL IN } /** * Returns a word frequency graph based on the input file. Words are sorted * based on frequency (more frequent words appear first) and then by name * (lexicographically). * * Convert all words into lower case for the analysis and graph generation. * * @return a word frequency graph based on the input file */ public String getFrequencyGraph() { return ""; // FIX ME } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!