Question
Write a Java program called Wordcount contained in 1 Java source file named Wordcount.java that reads words (i.e. tokens) from an input file and prints
Write a Java program called Wordcount contained in 1 Java source file named Wordcount.java that reads words (i.e. tokens) from an input file and prints out the number of words of each length (i.e. number of characters)contained in the file. Your input file for this program !!MUST BE NAMED!! the_paragraph.txt. This file will be in the same folder as your source file.
For the following input, the output is shown below. The data indicates 7 words of length 1; 1 word of length 14 and 0 words of length 13 (since that data point is missing).
My Dear Fellow Clergymen:
While confined here in the Birmingham city jail, I came across your recent statement calling my present activities "unwise and untimely." Seldom do I pause to answer criticism of my work and ideas. If I sought to answer all the criticisms that cross my desk, my secretaries would have little time for anything other than such correspondence in the course of the day, and I would have no time for constructive work. But since I feel that you are men of genuine good will and that your criticisms are sincerely set forth, I want to try to answer your statement in what I hope will be patient and reasonable terms.
Output starts below this line -----------------------------
output below:
Length Count Graph 1 7 ******* 2 19 ******************* 3 19 ******************* 4 25 ************************* 5 10 ********** 6 13 ************* 7 5 ***** 8 2 ** 9 4 **** 10 7 ******* 11 1 * 12 1 * 14 1 * Output ends above this line -----------------------------
Hints / Assumptions:
Words will not be over 80 characters. Therefore, create an array of 80 integers to hold the counts for words of each length.
Do not report counts for words that have 0 instances in the file.
Use a max_length variable to keep track of the longest word youve read. That way, you only have to report on words up to that length.
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