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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!