Pig Latin is a fake language used as a childrens game A word

\"Pig Latin\" is a fake language used as a children\'s game. A word in English is \"translated\" into Pig Latin using the folio wing rules: If the English word begins with a consonant, move the consonant to the end of the word and add \"ay\". The fetter Y should be considered a consonant. If the English word begins with a vowel (A, E, I, O, or U), simply add \"way\" to the end of the word. (This is a simplified dialect of Pig Latin, of course.) Write your method so that it returns the pig latin translated original string. You may assume that the input does not contain digits, punctuation, or spaces. The input may be in any combination of uppercase or lowercase. The case of your output does not matter.

Solution

import java.util.Scanner;

public class PigLatin {

   /**
   * @param args
   */
   public static void main(String[] args) {
       System.out.print(\"Please enter a word: \");
       Scanner in = new Scanner(System.in);
       String engWord = in.nextLine();

       System.out.println(\"The word you passed is : \" + translate(engWord)
               + \" in Pig Latin!\");

   }

   /**
   * method to convert the string piglatin
   *
   * @param original
   * @return
   */
   public static String translate(String original) {

       char startLetter = original.charAt(0);
       if (startLetter == \'a\' || startLetter == \'e\' || startLetter == \'i\'
               || startLetter == \'o\' || startLetter == \'u\'
               || startLetter == \'A\' || startLetter == \'E\'
               || startLetter == \'I\' || startLetter == \'O\'
               || startLetter == \'U\') {
           original = original.concat(\"way\");

       } else {
           String startconso = \"\";
           if (original.charAt(1) == \'h\') {
               startconso = original.substring(0, 2);
               original = original.concat(startconso).concat(\"ay\");
               original = original.substring(2);
           } else {
               startconso = String.valueOf(startLetter);
               original = original.concat(startconso).concat(\"ay\");
               original = original.substring(1);
           }

       }
       return original;
   }
}


OUTPUT:
Please enter a word: srinivas
The word you passed is : rinivassay in Pig Latin!

Please enter a word: America
The word you passed is : Americaway in Pig Latin!

 \
 \

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site