Question
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
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