Question
I would require a program that translates a text to Fake Latin and back. It is done by taking the first letter of every word,
I would require a program that translates a text to Fake Latin and back. It is done by taking the first letter of every word, moving it to the end of the word and adding'ay'to each word. I was able to do half of it correctly i,e translating it to Fake Latin as shown in the below code but I'm unable to implement the reverse of it i,e translating it back to English. Could you please complete the code for reversing the text back to English.
import java.util.Scanner;
public class FakeLatin
{
public static void main(String[] args)
{
Scanner pig = new Scanner(System.in);
String word;
String latin = "";
char first;
boolean cap = false;
String line;
System.out.print("Enter the line to translate: ");
line = pig.nextLine();
pig = new Scanner(line);
while (pig.hasNext())
{
word = pig.next();
first = word.charAt(0);
if('A' <= first && first <= 'Z')
{
first = Character.toLowerCase(first);
cap = true;
}
else
cap = false;
if (first == 'a' || first == 'e' || first == 'i' || first == 'o' || first == 'u')
latin = word + "ay";
else
{
if(cap)
{
latin = "" + Character.toUpperCase(word.charAt(1));
latin = latin + word.substring(2) + first + "ay";
}
else
latin = word.substring(1) + first + "ay";
}
System.out.print(latin + " ");
}
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started