Answered step by step
Verified Expert Solution
Link Copied!

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 0,1,2,3,4,5,6,7,8,9
Lowercase Alphabet a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z
Uppercase Alphabet A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z
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, 1805, and the speaker was the well-known 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 1805. 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
...
+contains(item : Type) : boolean
+indexOf(item : 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.compareTo(Type) to
compare elements.

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_2

Step: 3

blur-text-image_3

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 SQL Server Wait Statistics

Authors: Enrico Van De Laar

1st Edition

1484211391, 9781484211397

More Books

Students also viewed these Databases questions

Question

How is communication defi ned?

Answered: 1 week ago

Question

What are the benefi ts of studying communication?

Answered: 1 week ago