CPSC 120B Fall 2003
Program 3: Gibberish
Due Wednesday, October 17
Problem
Write a program that reads in a phrase from the user and prints the
gibberish equivalent of that phrase. To translate a word into gibberish,
each syllable is transformed by inserting "idig" between
the leading consonant sound and the rest of the syllable. If there is
no leading consonant sound, "idig" is simply prepended to the syllable.
Study the examples below to be sure you understand the translation.
English Gibberish
------- ---------
chair chidigair
three thridigee
ant idigant
easy idigeasidigy
marvelous midigarvidigelidigous
fanatic fidiganidigatidigic
This is reminiscent of the PigLatin program in the text, but there
are a number of significant differences that you will need to attend to.
Input
One reason gibberish is harder to understand than pig latin is that it
modifies every syllable. This means that your program will need to be
able to tell where one syllable starts and another ends, which is not
an easily automated task. To get around this, your program should allow
the user to indicate where the syllable breaks are in the words that are
entered by inserting a delimiter of the user's choice. For example,
if the user chooses a period (.) as a syllable delimiter, he or she
would then enter
"doc.u.men.ta.tion" for the word "documentation".
Note that if the user does not use the delimiter when entering words to
be translated, only the first syllable will be transformed.
After establishing the syllable delimiter, your
program should keep reading and translating phrases (using that
same delimiter) until the user asks
to quit. To simplify things for the translator, you should require that the
phrases entered contain only letters, spaces, and delimiters.
If the user enters a phrase containing other characters, the program
should ask for another phrase until it gets one with only legal characters.
Output
Your program should print the gibberish equivalent of each phrase entered,
neatly labeled, all lower case.
Program Structure
You will need two classes for this program: GibberishTranslator (the
translator) and Gibberish (the main program). There are a number of
things to think about for each:
- GibberishTranslator: This class is similar to
the book's PigLatinTranslator, but it is somewhat more complex.
In particular:
- It needs to store the syllable delimiter as an instance variable of
type String.
- It should have two constructors, a default constructor that sets
the syllable delimiter to the empty string ("") and a constructor that
takes the delimiter as a parameter.
- It needs a (public) translate method and a (private)
translateWord method, but the translateWord
method will need to call a translateSyllable method for each syllable.
A StringTokenizer can be used to find each syllable; it has a constructor
that takes the delimiter between tokens in the string:
public StringTokenizer(String s, String delimiter)
So if you pass the strings "abc*de*1234" and "*" to the StringTokenizer
constructor, successive calls to nextToken will return "abc", "de", and
"1234". Note that the delimiter is not returned.
- To translate a syllable, you will need to find the leading
consonant sound, which could contain 0 or more letters. To do this
write a private method int getPrefix(String s) that returns the
index of the first non-consonant in s, then use the value it returns
to get both the first and last part of the syllable. Be careful of
the letter y; it usually acts as a consonant at the beginning of a
syllable but as a vowel everyone else, and you should treat it
appropriately in both cases.
- Gibberish: This driver gets the delimiter from the user, creates a
GibberishTranslator object, and then reads in and translates phrases until
the user asks to quit. The most complicated part of this is
verifying that the phrase does not contain any illegal characters.
You should write a separate (static) method to do this (and that method
might need to call one or more additional methods.)
Sample I/O
A single run of your program might look like this:
*** Welcome to the Gibberish translator!! ***
Enter the character that will delimit syllables: .
Enter phrase: This is a test
Your phrase in gibberish:
thidigis idigis idiga tidigest
Translate another phrase? (y/n) y
Enter phrase: Gib.ber.ish is ve.ry strange
Your phrase in gibberish:
gidigibbidigeridigish idigis vidigeridigy stridigange
Traslate another phrase? (y/n) y
Enter phrase: I don't like this!
Phrase contains illegal characters, enter again: Goodbye
Your phrase in gibberish:
gidigoodbye
Traslate another phrase? (y/n) n
Bidigye!
Documentation and Style
Provide a program header that gives your name, the name of the
file, and a description of the program.
Also provide a header for each method that gives its name, its parameters,
and its return value, and briefly explains what it does.
Use good names for
variables and constants, and use an explanatory comment whenever
a portion of code might not be clear to the reader.
Also be sure to
follow the capitalization conventions discussed in class.
What to Turn In
Turn in hardcopy of your program and e-mail the source code to
bloss@roanoke.edu. Put cs120 prog3 in the subject line.
Both the hardcopy and the e-mail are due by 4:00 on the
date above.