13.25 Word Histogram Design and implement a program called “WordHistogram.java” that creates a histogram that allows you

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

13.25 Word Histogram Design and implement a program called “WordHistogram.java” that creates a histogram that allows you

Post by answerhappygod »

13.25 Word Histogram
Design and implement a program called “WordHistogram.java” thatcreates a histogram that allows you to visually inspect thefrequency distribution of a set of words in a given file. Theprogram should read the input filename as a command-line argument.A word is defined as a collection of letters a-z and A-Z
For example, if the input file is:
How much wood would a woodchuck chuckIf a woodchuck could chuck wood?He would chuck, he would, as much as he could,And chuck as much wood as a woodchuck wouldIf a woodchuck could chuck wood.
The output file will contain:
a : 4and : 1as : 4chuck : 5could : 3he : 3how : 1if : 2much : 3wood : 4woodchuck : 4would : 4Hint:create a StringBuilderWhile(inputFile.hasNext()){Read a lineadd “\n” to end of lineappend the line to the buffer replacing all non alphabeticalcharacters with “\n”String s1 = s.replaceAll("[^a-zA-Z]+","\n").toLowerCase();}Create an array of String by splitting the buffer //split("[^a-zA-Z]+")Create an ArrayList from your String arraysort the ArrayListAdd up unique wordsprint the result
USE JAVA
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply