Solution to f7c3: Pig Latin
See code at solutions/code/tutorialquestions/questionf7c3
The sample code solution declares a method translateToPigLatin that
translates a string, assumed to be alpha-numeric, into Pig Latin. Static method isDigit of
the Character class, and
the charAt instance method of String are used to check whether the first character of
the input string is a digit; if this is the case the string is returned unchanged. Otherwise, the
Pig Latin transformation is performed relatively straightforwardly using a helper method, isVowel.
The solution illustrates the use of the substring method on strings, and Java's ternary
operator:
b ? e1 : e2
which evaluates to e1 if Boolean expression b holds,
and to e2 otherwise.
Method translateLineToPigLatin is responsible for splitting up a line into individual words,
which are processed by translateToPigLatin. The main method uses a BufferedReader
to process lines from standard input.