Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Given Assignement3driver: import java.io.*; public class Assignment3Driver { public static void main(String args[]) { Assignment3 a3 = new Assignment3(args[0]); try { a3.processFile(); System.out.println(There are

Given Assignement3driver: import java.io.*; public class Assignment3Driver { public static void main(String args[]) { Assignment3 a3 = new Assignment3(args[0]); try { a3.processFile(); System.out.println("There are " + a3.getWordCount() + " words in the file " + args[0]); System.out.println("The most frequent word in " + args[0] + " is: " + a3.getMostFrequentWord()); } catch(IOException e) { e.printStackTrace(); } } } 

Write a new class named Assignment3.

Requirements:

1. Add two private member variables, one to store the name of the file, and another to store the count of words in the file.

2. Add a public constructor. Its only argument is the name of the file. Use it to initialize one of the variables from requirement #1.

3. Add a public "getter" for the word count, name it "getWordCount".

4. Add a public function named "processFile". It returns nothing and accepts no arguments. This function will:

a) Open the file.

b) Read the file's contents into a buffer.

c) Close the file.

d) Convert the buffer into a string.

e) Tokenize the string and use the tokenizer to initialize your word count variable.

5. Add a private member variable that will store the most frequent word in the file.

6. Add a "getter" for the variable (of #5)

7. Add code to your processFile function that counts the number of times each word appears in the file. A HashMap is a good choice for this.

8. Add code to your processFile function that loops through your HashMap (if that's what you use) to find the most frequent word. After your loop, the variable added (for #5) should contain the value for the most frequent word. Don't worry about ties

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

Pro Database Migration To Azure Data Modernization For The Enterprise

Authors: Kevin Kline, Denis McDowell, Dustin Dorsey, Matt Gordon

1st Edition

1484282299, 978-1484282298

More Books

Students also viewed these Databases questions

Question

What is Change Control and how does it operate?

Answered: 1 week ago

Question

How do Data Requirements relate to Functional Requirements?

Answered: 1 week ago