Skip to content

Instantly share code, notes, and snippets.

@dcoles
Created November 2, 2012 04:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dcoles/3998795 to your computer and use it in GitHub Desktop.
Save dcoles/3998795 to your computer and use it in GitHub Desktop.
Igpay Atinlay
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);
}
}
}
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