Problem: Design and implement a class called WordProcessor. This class is
? hold a line of text that can be manipulated in various ways
? perform various manipulations and modify the text
? return a string with a list of all the palindromes in the text (a palindrome
reads the same forwards as backwards)
? return a Pig Latin version of the text (see description below)
? return several counts about the text
o number of words (a hyphenated word is one word),
o number of sentences (ends in a period),
o number of questions (ends in a question mark),
o number of exclamations (ends in an exclamation mark!),
Helpful information and requirements for your WordProcessor class - you must
name your methods exactly as shown here:
? You can break up a String into words or "tokens" by using java?s Scanner
class. When constructing your Scanner, you will pass a String as a
parameter (not System.in). The Scanner methods necessary to break it
up are hasNext() and next(). See the ScannerDemo.java posted on our
class webpage to see how this works.
? Legal punctuation for the text is periods, question marks, exclamation
marks, hyphens (within a word), and apostrophes. Words will have only a
single space between them.
? Your class should have 2 constructors: one that has no parameters and
a second one that takes a line of text as a parameter. Each constructor
should initialize all instance variables.
? Write a public method setText that takes a String parameter and changes
the current text to this new String. If no text existed before, this sets it. If
there was text, this method will overwrite it. It doesn't return anything.
? Write a public method toString that takes no parameters but returns the
current version of the text.
? Write public methods getNumberOfWords, getNumberOfSentences,
getNumberOfQuestions, getNumberOfExclamations that return the counts
of how often each of these things occur in the text.
? Write a public method replaceWord that takes two String parameters. The
first parameter is the word to replace, the second parameter is what
to replace it with in the text. All occurrences of the first word should be
changed to the second. This method does not return anything. You
may not use the String method replace, replaceAll, or
? Write a public method appendText that takes a String parameter and
appends (adds it to the end) it to the current text. If no text existed before,
this sets it. It doesn't return anything.
? Write a public method getPalindromes that takes no parameters, but
returns a String that has all the words in the text that are palindromes
concatenated together, each one separated by a space. A palindrome
reads the same forward as backwards ignoring case and internal
punctuation). For example: noon, Sara?s, radar are all palindromes.
? Write a public method getPigLatinVersion that takes no parameters, but
returns the Pig Latin translation of the text. This method does not modify
or change the original text. You may want to have one or more "private"
methods to help this method do its work. To convert a word to Pig Latin:
o if the word begins with a vowel (a, e, i, o, u), then just add ?ay? at the
end of the word.
o if the word begins with one or more consonants, move all initial
consonants (up to the first vowel) to the end of the word and add ?ay? at
o if the word is all consonants, then just add ?ay? at the end.
o leave any internal punctuation (apostrophes and hyphens) where it is
in the original string. For example Sara?s becomes Ara?ssay
o word separators such as commas, periods, etc. should not be included
in the middle of a Pig Latin version of a word but should occur after the
word as before.
o if the original first letter of a word is capitalized, the Pig Latinized
version of the word should also begin with a capital letter.
? Start early! This assignment will take some involved problem solving
? Work up your solution incrementally as we've discussed in class. For
example, initially make sure that each of your constructors work. Then add
other methods such as the number of words, sentences, etc.
? If you?re having trouble making it work with capitalization and punctuation,
use a simplified input with all lower case letters and no punctuation, then
work up from there.
? You should always have a compiling, working class at each stage of
? Ask questions!