Tuesday, April 29, 2003

Feeling OK but busy.

I have to encounter the maths test (but feeling good.) But the computer test is not very well (but everybody who has participated in the test are just like me.) The 3rd computer test is better, and the computer projects are more challenging, the project 3 is having more points but also harder.


Here is the requirement of the project 3


Project 3: Pig Latin Translator                                    Points: 40



 


The Program:


Your program will translate an English sentence (provided by the user) into Pig Latin and display this result on the screen.



 


Notes:


Examine the sample output below and attempt to duplicate it.  Remember that the user will enter the String, so your program must be able to adapt in response to this input.    


 


The simple rules for building a Pig Latin word from a normal English word are:




  1. if the first letter of a word is a vowel, append way to the end of the word.  E.g. and becomes andway; is becomes isway; a becomes away; etc.

  2. if the first letter of a word is a consonant, move the first letter of the word to the end and add ay.  E.g. hello becomes ellohay; the becomes hetay; Java becomes avajay. 


There are more complex rules for the Igpay Atinlay connoisseur, but the rules above will be sufficient for this program.


 


Your program should generate the following sample dialog if given the input shown in bold below:




Welcome to the Pig Latin Translator.


 


Enter a sentence to be translated:


> Hello my name is Bob!


 


Your sentence, translated into Igpay Atinlay, reads:


 


elloHay ymay, amemay isway ob!Bay


 


Thank you for using Bob's Pig Latin translator.



 


The dialog above is sufficient for full credit, but it is pretty ugly.  The capitalization and punctuation was not taken into account and therefore corrupted the translation.  A better translator would produce the following:




Welcome to the Pig Latin Translator.


 


Enter a sentence to be translated:


> Hello my name is Bob!


 


Your sentence, translated into Igpay Atinlay, reads:


 


Ellohay ymay amemay isway Obbay!


 


Thank you for using Bob's Pig Latin translator.



 


In this improved version capitalization was moved to the new front of the word and punctuation was appropriately moved to the back of the word.  You shouldnt assume capitalization or punctuation.  You only have to handle the capitalization and punctuation that you find.  E.g. Hello! should be transformed to Ellohay!, but hello should transform to ellohay.  Two points of extra credit if you manage the capitalization and two points of extra credit if you manage the punctuation.  Thats a total of ourfay ointspay extraway (four points extra)!


 


The program requires the use of a loop to sequentially process the input string.  The actual processing can be done in many ways, but I recommend the String method indexOf to find the spaces that separate words.  Once these spaces are found you can use the String method substring to obtain the actual words.  With a word in hand, you can split it apart (if necessary) using charAt and substring to build and display the Pig Latin equivalent.

No comments: