Question
Problem description : Given a text file, you need to compute the frequency of each word in the file. Consider the following Class : Variables:
Problem description: Given a text file, you need to compute the frequency of each word in the file.
Consider the following Class :
Variables:
word: the word (String)
count: the frequency of the word (int)
Methods
WordFrequency(String wf)
//the constructor sets the word, initialize count = 0
getWord() and getCount()
//the getter methods
incCount()
//increment the count
class TestClass
main Method:
Open the text file
Create wordList as a new ArrayList of WordFrequency
while (not end of file)
read the next String as word
if(word is in wordList)
Increment count of the corresponding word
else
add word to wordList, initialize count to 1
print all words (with count) in the wordlist that have frequency (i.e., count) at least 2 4
Sample Input File
Information Technology (IT) is becoming the cornerstone to any economy in the world. Since the spread of the Internet and communication applications in their diversified forms, IT became an integrated part of everyone's life in modern society. In UAE, IT plays a major role in the development of the society. Therefore, it is only natural to have the United Arab Emirates University offer a degree program in IT in its various specializations. The College of Information Technology offers a bachelor of science degree in Information Technology (BSc in Information Technology) in seven specialization tracks: Intelligent Systems (INSYS), Software Development (SWD), Information Security (SEC), Networking (NETW), E-Commerce (ECOM), Enterprise System (ENSYS), and Computer System Design (CSD).
WordFrequency -word: String count: int +WordFrequency(String) +getWord): String +getCount): int +incCount): voidStep 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