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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started