CSC 171 LAB #10
FALL 2001
GOAL:
1.
Become
familiar with Strings, StringBuffers, and methods of String manipulation
2.
Become
familiar with the design of flexible implementations
TASKS:
1.
Write
a program that encodes English into Pig Latin (RITEWAY A ROGRAMPAY HATTAY
NCODODESEAY NGLISTHEAY NTOIAY IGPAY ATINLAY).
2.
Your
program must run 3 ways:
·
As
an applet
·
As
a J/Frame application invoked from the command line
·
As
a command line application without any GUI
NOTE: This does NOT mean that you write three programs – you write one program that can run 3 ways.
BACKGROUND:
Pig Latin (IGPAY ATINLAY) is a
form of coded language often used for amusement. Many variations exist in the
methods used to form Pig Latin phrases. We will consider a simplified approach.
The form a pig Latin phrase from
an English language phrase you need to break up the phrase into the individual
tokens. To translate each English word into a pig Latin word, place the first
letter of the English word at the end of the word and add the letters “ay”.
Thus the word “jump” becomes “umpjay”, the word “the” becomes “hetay”, the word
“computer” becomes “omputercay”. Single letter words just get the suffix : “I”
becomes “iay”, “a” becomes “aay”. Blanks remain as blanks. With a very small
amount of practice, you can do this in your head and carry on secret
conversations with your computer science friends in public places that those
from other majors will only be able to gape at.
STEPS:
1.
Begin
by thinking about the design, the program must be flexible, so it makes sense
to have a “pig Latin converter class” that can be used in the context of
several methods of devlivery.
2.
The
converter class must have methods to convert words from English to pig latin,
from pig Latin to English. It should also have methods that work on whole
phrases.
1.
The
converter methods should take Strings in and return Strings
2.
How
can we get such methods? Hint: What happens when you StringTokenize a string
with a single token?
3.
Write
a method that converts a single word from English to Pig Latin.
1.
There
are lots of ways to do this, but the StringBuffer class, described in your book
seems very useful. Your method might build a StringBuffer out of the String,
perform the manipulations and convert back to a String for return.
4.
Same
as previous step, but go the other way : Pig Latin to English
1.
If
the word is not a legal pig Latin word, then return it unchanged.
5.
Write
methods that take more general strings, tokenize them, send the tokens to the
word converter and build up the return string.
6.
At
this point, you are pretty much done with the Pig Latin “engine”. This should
be a separate class (think Modular programming). The methods that operate on
words only should be private methods. The public methods should be the ones
that deal with the StringTokenization.
7.
Review
the code from D&D Section 13.7 that was gone over in lecture.
1.
Pay
special attention to the use of the command line args.
8.
As
mentioned above your program must run in any of three ways without any
recompilation. The techniques used for applet/application dual used is the
subject of sec 13.7
1.
The
GUI needs only have two text areas : one for English text, one for Pig Latin
text. When the user types in strings in the English text box, convert and stuff
the result into the Pig Latin box, and vica-versa (your program must work both
ways). So, you need an associated html file.
2.
You
don’t need to do a fancy layout for the lab – but it would be nice, now
wouldn’t it?
9.
In
addition to running as an applet/FrameApplication your program must run directly
from the command line. In order to do this implement a command line argument
“-nowindow”. If your program is invoked from the command line using the “-no
window” flag, then it should just convert the remaining tokens on the command
line and print them to standard output.
10.
Your
program should also support a “-reverse” flag in order to convert from Pig
Latin back to English.
11.
So,
if you invoke your program with
java –classpath myjar.jar
myPigLatinConverter –nowindow covert these words to pig latin
Your program should respond with
overtcay hesetay ordsway otay igpay atinlay
to Standard.out
12.
Use
the Java archive utility to combine them into a single archive file.
13.
When
you get the paper ready call your lab TA over and demo the program for her/him.
Give the paper to your TA. This completes the hand in process. The deadline is
one week – no late assignments accepted.
14.
The
demo must run from the local machine. All that should be in the directory is
your jar file and your html file. Use a command line invocation for the both
the window and non window application and load the html into the browser.
15.
Be
sure to start talking Pig Latin to your friends at parties in order to impress
members of the opposite sex.