Question
Write a new class named TextProcessor, which of course means that the file name must be TextProcessor.java. This class will open a text (input) file,
Write a new class named TextProcessor, which of course means that the file name must be TextProcessor.java. This class will open a text (input) file, read its contents, and compute statistics regarding the words contained within the file.
Requirements
-
Include the required comment and comply with its terms. Solutions which fail to include the required academic integrity comment will not be graded.
-
Add a public constructor. Its only formal parameter (argument) is a String reference which contains the name of the input file. The input file is a simple text file that you can create with a text editor such as Windows Notepad. You will need to do something with this reference...
-
Add a private method named processTextFile(). Call, aka execute this method from within your constructor. It returns nothing and accepts no arguments. This function will:
-
Open the input file.
-
Read the files contents.
-
Close the file.
-
Convert the file contents into a String or many String objects.
-
Tokenize the String contents. You may not use String.split() or any regular expression code. Use the StringTokenizer class for this requirement. Why? It is exceptionally hard to get the counts right with any other class. Failure to use StringTokenizer will cost you points.
-
Handle all Exceptions within the body of the processFile() method. That is, the test harness must be blissfully unaware of any need to handle any Exception. Hint: if the keyword throws appears in your file, then you have failed this requirement.
-
You may find that it is useful to place additional code in this method that will help you solve other requirements below. For example, you may choose to keep a running total of the number of words/tokens you process here and save that total as a member variable.
-
-
Add a public "getter" for the word count, name it getWordCount(). Return, as a value of type int, the number of words contained within the input file. For example, if the input file contains only "this is a short file", then the return value from this method is 5.
-
Add a public getter for the file length, name it getFileLength(). Return, as a value of type long, the length of the file as measured in bytes. To know what this value should be, open either Windows Explorer or the Finder and look at the details for your test input file.
-
Add a public getter for the file name, name it getFileName(). Return a reference to a String object that contains the name of the input file.
-
Add a public method named countThisWord(). It accepts a reference to a String object, and you will find out how many times this specific string (or word or token) appears in the input file. Return the count as a value of type int. For example, if the input file contains only "this is very very hard", and the word that you are counting is "very", then the return value from this method is 2.
-
Add a public method named getWordsHavingCount(), which accepts an int argument, the count. The return type is List. Return a reference to a List object where that object contains all words that appear count times in the input file. For example, if your input file contains only This is very very difficult and you execute this method with the argument value 2, then the returned List will contain only the word very.
-
Add a public method named getWordsHavingLength(), which accepts an int argument. The return type is List. Return all words that have the number of characters specified by the argument. For example, if your input file contains only: This is an example and you execute this method with the argument 2, then this method will return a List containing two String references: (is, an).
-
Add a public method named getMostFrequentWord(), which accepts no arguments. The return type is String. Ignore the possibility of a tie. Tell me which word appears most often in the input file.
-
Add a public method named getAverageWordCount(), which accepts no arguments and returns the average of the word counts as a float value. For example, if your input file contains only This is very very hard, then the average is 1.25, using counts (1, 1, 2, 1) for this, is, very, hard respectively.
-
Add a public method named getUniqueWordCount(), which accepts no arguments and returns the count of unique words as an int. For example, if your input file contains only This is very very hard, then the unique word count is 4.
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