Created
November 2, 2012 04:55
-
-
Save dcoles/3998795 to your computer and use it in GitHub Desktop.
Igpay Atinlay
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.BufferedReader; | |
import java.io.IOException; | |
import java.io.InputStreamReader; | |
public class Main { | |
/** | |
* @param args the command line arguments | |
*/ | |
public static void main(String[] args) { | |
// 1. Prompt user for input | |
System.out.println("Please type your sentence, and it shall be translated."); | |
// 2. Read in a line of input and split into an array of Strings | |
PigLatinator pl = new PigLatinator(); | |
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); | |
try { | |
String line = reader.readLine(); | |
String[] words = line.split("\\s"); | |
// 3. Loop over the words and call latinate() on each one and print the result | |
for (int i=0; i<words.length; i++) { | |
System.out.print(pl.latinate(words[i]) + " "); | |
} | |
System.out.println(); | |
} catch (IOException ex) { | |
System.err.println("IO Error " + ex); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PigLatinator { | |
String latinate(String word) { | |
// 1. Decide if the word starts with a vowel or a consonant | |
boolean isVowel = true; | |
if (isVowel/* vowel */) { | |
// 2a. If it starts with a vowel return the word + "way" | |
return word; | |
} else { | |
// 2b. Otherwise return the word without the first character + first character + "ay". | |
return word; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment