Solved by verified expert:java assignment 02java assignment 02java assignment 02
2018spring_cs117_hw02.zip

2018spring_cs117_hw02_assignment.pdf

Unformatted Attachment Preview

Name
CS117 – Homework 02 – Page 1
Homework 02: Text Statistics
Assigned: Friday, February 2, 2018
Due: Friday, February 9, 2018 at 6:00am
1
Background
People often examine written documents to try to determine who wrote them: historians who find
a play that might have been written by Shakespeare, teachers who find a term paper that might
have been written by someone other than the student who turned it in, detectives who want to
know whether the same person wrote two ransom notes for different kidnapping victims, and so
forth.
Computers can help with this kind of work by quickly analyzing documents and gathering
statistics about them. One of the simplest kinds of statistics that could be collected is the number
of times (frequency) that each word appears in two different documents. If each word appears
around the same number of times in both documents, that is evidence that they were written by
the same person. If there are a few words that appear very often in one document but not the
other, that is evidence that they were written by different people.
2
Assignment
Download the 2018spring-cs117-hw02.zip file from Moodle, and unzip it to find the directory
CS117-HW02. Open that project in BlueJ. You will find that the project already contains a Main
class, and that this class has a small static method that I wrote for you, called cleanUpWord, and
an empty main method.
Write a program in the main method that allows the user to type in a document, ending their
document with the special word “@DONE@”. While the user types in the words, your program
should be keeping track of how many times each word has appeared. Think about what classes
we have learned about that might be useful for this. We want to ignore case and punctuation, so
use the cleanUpWord method to turn every word into a standardized, capitalized version with the
punctuation stripped out. (But not before checking to see if it is “@DONE@”!)
Then your program should allow the user to type in a second document and collect (different)
statistics on it. Then it should show a list of all words that appeared in at least one document,
with the count of how many times it appeared in the first document followed by how many times
it appeared in the second document. Do not attempt to output the words in any particular order.
See the end of this file for an example session.
3
Sample Session
Type an entire document, then ‘‘@DONE@’’ when you are finished.
If you give a mouse a cookie, he’s going to ask for a glass of milk.
When you give him the milk, he’ll probably ask you for a straw.
When he’s finished, he’ll ask for a napkin.
Name
CS117 – Homework 02 – Page 2
Then he’ll want to look in a mirror to make sure he doesn’t have a milk moustache.
When he looks into the mirror, he might notice his hair needs a trim.
So he’ll probably ask for a pair of nail scissors.
@DONE@
Type another entire document, then ‘‘@DONE@’’ when you are finished.
I went to sleep with gum in my mouth and now there’s gum in my hair
and when I got out of bed this morning I tripped on the skateboard and
by mistake I dropped my sweater in the sink while the water was running
and I could tell it was going to be a terrible, horrible, no good
very bad day.
@DONE@
A count of how many times each word appeared in each document:
3
0
MILK
1
0
NAPKIN
1
0
STRAW
1
0
WANT
1
0
SCISSORS
1
1
GOING
9
1
A
1
0
MOUSTACHE
3
2
TO
2
3
THE
1
0
COOKIE
1
0
MOUSE
1
0
SURE
1
1
HAIR
4
0
ASK
1
0
MAKE
4
0
FOR
1
0
LOOK
2
0
GIVE
2
1
OF
1
0
IF
1
0
NOTICE
1
0
NEEDS
3
0
HE
2
0
HES
1
0
HIM
1
3
IN
1
0
THEN
1
0
DOESNT
3
1
WHEN
1
0
SO
Name
1
1
1
2
2
1
1
1
1
1
1
3
4
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
1
1
1
5
1
1
1
1
1
1
1
1
1
1
1
4
1
1
1
1
1
1
3
1
1
1
1
2
CS117 – Homework 02 – Page 3
FINISHED
TRIM
HAVE
MIRROR
PROBABLY
PAIR
NAIL
MIGHT
LOOKS
HIS
INTO
YOU
HELL
GLASS
VERY
BY
WHILE
TERRIBLE
I
NO
SLEEP
SKATEBOARD
WENT
ON
WATER
GOT
NOW
DAY
RUNNING
BE
AND
SINK
COULD
TRIPPED
THERES
HORRIBLE
MORNING
MY
OUT
BAD
IT
MOUTH
WAS
Name
CS117 – Homework 02 – Page 4
0
0
0
0
0
0
0
0
0
1
1
1
2
1
1
1
1
1
TELL
THIS
DROPPED
GUM
BED
GOOD
SWEATER
MISTAKE
WITH
4
Finishing Up
Make sure that your classes compile, behave as expected, and have complete documentation. Also
ensure that they use good programming style. In the previous lab we introduced the Checkstyle
feature, which you should use to confirm that you are obeying our style guidelines.
Close BlueJ and create an archive file of your CS117-HW02 folder. Then upload that archive file
to Moodle.

Purchase answer to see full
attachment