Question: PART 1 Design and implement a program called WordHistogram.java that creates a histogram that allows you to visually inspect the frequency distribution of a set

PART 1

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:

While(inputFile.hasNext())

{

Read a line

add to end of line

create a StringBuffer

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

PART 2

test your program using the infile.txt

infile.txt 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. 

PART 3

2 files are needed, WorldHistogram.java and outfile.txt

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!