Question: Can anyone please help me with this problem? STAGE 1 | (Word Histogram) Design and implement a program called WordHistogram.java that creates a histogram that
Can anyone please help me with this problem?
STAGE 1 | (Word Histogram)
Design and implement a program called WordHistogram.java that creates a histogram that allows you to visually inspect the frequency distribution of a set of word in a given file. The program should read the input filename and output filename as command line arguments. A word is defined as collection of letters a-z and A-Z
For example if the input file is:
How much wood would a woodchuck chuck If a woodchuck could chuck wood? He would chuck, he would, as much as he could, And chuck as much wood as a woodchuck would If a woodchuck could chuck wood.
The output file will contain:
a:4 and : 1 as: 4
chuck : 5 could : 3
he: 3 how: 1
if: 2 much : 3 wood : 4 woodchuck : 4 would : 4
Hint: create a StringBuilder While(inputFile.hasNext()) {
}
Read a line add to end of line
append the line to the buffer replacing all non alphabetical characters with
// String s1 = s.replaceAll("[^a-zA-Z]+"," ").toLowerCase();
Create an array of String by splitting the buffer sort the array Add up unique words print the result in the output file
STAGE 2 | Testing
Download (Google Drive) infile.tx and test your program as follows: Java WordHistogram infile.txt outfile.txt
Here is the file infile.txt
How much wood would a woodchuck chuck If a woodchuck could chuck wood? He would chuck, he would, as much as he could, And chuck as much wood as a woodchuck would if a woodchuck could chuck wood.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
