Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

-Write in java Write a program that reads a text file and counts the number of times each English word appears. Display the 25 most

-Write in java

Write a program that reads a text file and counts the number of times each English word appears. Display the 25 most frequently used words. The program requires two classes, the main program and a separate class called UseCount to hold a word and its count. The UseCount class needs two instance variables, one String to hold the English word and an int to hold the count of times this word appeared in the text. A constructor for UseCount should have one parameter to initialize the English word. The count should be initialized to one. The main program needs to sort an array of UseCount objects. To be sorted, the UseCount class must implement the Comparable interface and include a method compareTo. The class statement for UseCount should look like:

image text in transcribed

image text in transcribed

CatInTheHat.txt: https://docs.google.com/document/d/1f6UBKr6xmpTYApgak2_ZfbR_HWxj_tHfswFp5Bw25jg/edit

Frankenstein.txt: https://docs.google.com/document/d/1wWoIHdWgp8WwwKUcMOshit8f8aReelo7-JjBLcm9SGg/edit

PeterRabbit.txt: https://docs.google.com/document/d/1G2d_CDIQ-hRhIbXJGUo_EZ3bXBxAxuLP_g3-UWnGg9k/edit

Write a program that reads a text file and counts the number of times each English word appears. Display the 25 most frequently used words. The program requires two classes, the main program and a separate class called UseCount to hold a word and its count. The UseCount class needs two instance variables, one String to hold the English word and an int to hold the count of times this word appeared in the text. A constructor for UseCount should have one parameter to initialize the English word. The count should be initialized to one The main program needs to sort an array of UseCount objects. To be sorted, the UseCount class must implement the Comparable interface and include a method compareTo. The class statement for UseCount should look like public class UseCount implements Comparable { and the compareTo method in UseCount should be For sorting with the Comparable interface/ public int compareTo(UseCount othe return other.count - this.count; The main program should create an array that can hold 10,000 UseCount objects. After asking the user for the input filename, it should read one English word at a time from the file using the next method of a Scanner object. Convert the word to lower case so it will be easy to compare. For each word read, search the array of UseCount objects for an object that contains the word just read. If found, increment the count in that object. If not found, create a new object for that word and put it in the array. You will want to keep a count of the number of UseCount objects in the array After all words have been read from the input file, you can sort the array of UseCount object in descending order by the count. There is a static method to sort an array of objects java.util.Arrays.sort( wordList, 0, numWords ; where wordList is your array of UseCount objects and numWords is the number of objects in the arra The first 25 elements of the array will contain the 25 most commonly used words. Print the top 25 words and the number of times they appeared

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

What does Processing of an OLAP Cube accomplish?

Answered: 1 week ago