Pig Latin

advertisement

Pig Latin

Basic Rules

Pig Latin is a pretend language. The basic rule is simple: move the leading consonants to the end of the word and append "ay". pig -> ig-pay latin -> atin-lay this -> is-thay strange -> ange-stray bcdfgh -> **** INVALID *****

If the first letter is a vowel then just append "way". apple -> apple-way eye -> eye-way

Write a program that translates words from English to Pig Latin. Pass a string with multiple words and return the phrase in Pig Latin.

We’ll use the hypen, ‘-‘, to simplify translation from Pig Latin to English

Special Cases

If the first vowel is a "u" and the letter before it is a "q" then the "u" also goes to the end of the word. question -> estion-quay squeeze -> eeze-squay

Treat "y" as a consonant if it's the first letter of a word; otherwise, treat "y" as a vowel if it appears earlier than any other vowel. yes -> es-yay rhyme -> yme-rhay try -> y-tray

Modify your program to handle these special cases.

Part 1: write a program to translate a sentence from English to Pig

Latin and from Pig Latin back to English

Scanner Class

I suggest you hard code a sentence first so that you can get the translator to work:

String str1 = new String (“you smell like apples”);

Use the Scanner class to parse your sentence:

Scanner input = new Scanner(myString);

Use the hasNext() method to determine if there are additional words in your sentence which need to be translated. Use next() to parse the word.

Part 2:

Capitalization and Punctuation

If a word is capitalized in English then it should be capitalized in Pig Latin also.

Thomas -> Omas-thay

Jefferson -> Efferson-jay

If external punctuation is used in English then it should remain in Pig Latin.

What? -> At-whay?

Oh! -> Oh-way!

"hello" -> "ello-hay"

"Hello!" -> "Ello-hay!"

Modify your program to handle capitalization and punctuation.

Download