[Univ of Mississippi]
[Computer & Info Science Dept]
Tuesday, January 12, 1999 10:54:28 AM
CSCI 517 Natural Language Processing (Spring 1999)
Programming exercise #2: due Monday January 25
Pig Latin Applet
The purpose of this exercise is to give you some experience
in writing a Java applet that manipulates the words in a sentence.
This exercise is based on exercise #8.11 on page 461 of the Deitel Java textbook,
but follow the instructions as stated here.
Write a Java applet that allows the user to type in a sentence,
e.g. in a simple TextField.
Convert the sentence to "Pig Latin" and display that new sentence
in another TextField.
Here is the rule for conversion of a word to Pig Latin. Find the position of the first
vowel in the word. Move all characters preceding that vowel (if any) to the end of the word,
then append the string "ay". For example, "computer" becomes "omputercay", "the" becomes "ethay", "eleven" becomes "elevenay", and so on.
Note that the letter "y" can act as a vowel in some English words. For example,
"dry" becomes "ydray", "zygote" becomes "ygotezay", but "yellow" becomes "ellowyay".
Java makes it easy to break a sentence down into the individual words. See the Deitel Java
book, figure 8.20, for an example of use of the StringTokenizer class. That program was
the origination point for development of the applet shown below.
Other Java String methods that you might find useful include toLowerCase, substring,
indexOf, and so forth.
Here is output from an applet that illustrates what your interface might look
like. The applet that produced this output was about 80 lines of code, including
the usual number of blank lines.
Also, if your browser supports JDK 1.1,
click here to see the PigLatin applet
that produced the above output display in action.
Dr. Schoenly's courses: http://cs.olemiss.edu/~sbs/
Computer Science Dept
Can't find what you are looking for?
Email email@example.com or