Answered step by step
Verified Expert Solution
Question
1 Approved Answer
The Task: I have a text file version of Leo Tolstoy s War and Peace. I would like to extract all the unique words in
The Task: I have a text file version of Leo Tolstoys War and Peace. I would like to extract all the
unique words in the file and sort them as the first step to counting the number of occurrences
of each word in the book well do this in a future assignment We will do this by following this
simple pseudocode:
For each word in the text:
If the word is not in the list, add it to the list.
This code uses a search to find if the word is in the list, and the add method to add new words
to the list.
In order to perform this task we need to know what counts as a word for the purposes of the
task. So for the purposes of this assignment we will define a word as any string of
consecutive alphanumeric characters or apostrophes. Specifically, this means a word is any
string of characters from this set:
Numerals
Lowercase Alphabet abcdefghijklmnopqrstuvwxyz
Uppercase Alphabet ABCDEFGHI,JKLMNOPQRSTUVWXYZ
Apostrophe
We will treat all other characters as separators. A word always has a separator before and after
it in the text except possibly the first and last word Here are some examples using a line of
text from War and Peace to make sure we understand this idea.
It was in July, and the speaker was the wellknown Anna Pavlovna
Scherer, maid of honor and favorite of the Empress Marya Fedorovna.
Most words in this text are preceded and followed by a space. In this text we can see the words
July and Both of these words are preceded by a space and followed by a comma.
The words well and known are separated by a hyphen. In these examples the spaces,
commas, and hyphens are the separators.
To complete this you will upgrade two classes, implement three public classes:
MyLinkedList with a protected Node
MyArrayList
MyOrderedList
BookReader
UniqueWords
Formal Specifications
MyArrayList
comparisons : long
containsitem : Type : boolean
indexOfitem : Type : int
sort
Field summary
comparisons Stores the total number of comparisons made by the array list.
In contains place one comparisons inside the loop.
Method summary
contains This function should be upgraded to use Comparable.compareToType to
compare elements.
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