Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Complete the following coding in java Write a program that reads a text file and counts the number of times each English word appears. Display

Complete the following coding in java
image text in transcribed
image text in transcribed
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 compare To method in UseCount should be: *For sorting with the Comparable interface/ public int compareTo(UseCount other return other.count -this.count; The main program should create an a 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 in the array. You will want to keep a count of the number of UseCount objects in the array rray that can hold 10,000 UseCount objects. After asking the user 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, ,numWords) where wordList is your array of UseCount objects and numWords is the number of objects in the array 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 appear

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

Big Data Fundamentals Concepts, Drivers & Techniques

Authors: Thomas Erl, Wajid Khattak, Paul Buhler

1st Edition

0134291204, 9780134291208

More Books

Students also viewed these Databases questions