I have to write a program that converts whole phrases to pig latin . He must read the phrases from the file, and then translate and print the pigs in Latin.
This should be read in the text from the file. The keyboard must be NO.
This is my example text file:
This is a test
Here is the second line
and third
The output should be the original phrase, followed by its version for pork latin. Both versions must be surrounded by quotation marks on the output.
"This is a test" in Latin American gilts - this is the "Tay way on the road,"
"Here is the second line" in lead latin "ere-Hay - one way" say, unscathed
", " "-" -way a-way ird-thay "
, , . . ?
:
import java.util.Scanner;
import java.io.*;
public class pigLatin2 {
public static void main(String[] args) throws FileNotFoundException {
Scanner input = new Scanner(new File("phrases.txt"));
while (input.hasNextLine()) {
String line = input.nextLine();
System.out.print("\"" + line + "\"" + " in pig latin is \"");
Scanner words = new Scanner(line);
while (words.hasNext()) {
String word = words.next();
String pigLatin = pigLatinWord(word);
System.out.print(pigLatin + " ");
}
System.out.println("\"");
}
}
public static String pigLatinWord(String s) {
String pigWord;
if (isVowel(s.charAt(0))) {
pigWord = s + "-way";
} else if (s.startsWith("th") || s.startsWith("Th")) {
pigWord = s.substring(2) + "-" + s.substring(0,2) + "ay";
} else {
pigWord = s.substring(1,s.length()) + "-" + s.charAt(0) + "ay";
}
return pigWord;
}
public static boolean isVowel(char c) {
String vowels = "aeiouAEIOU";
return (vowels.indexOf(c) >= 0);
}
}
: " " , "is-Thay is-way a-way est-tay"