Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a java application that acts as a one-word Pig Latin translator. Your program should: ask the user to enter a word convert the entered

Write a java application that acts as a one-word Pig Latin translator. Your program should:

ask the user to enter a word

convert the entered word into proper Pig Latin translation

print the translated word on the screen

I have the following code, I just need it to be fixed so that the following condition is met. (currently whenever "xylophone" is entered, the program prints "ophonexylay", when it should print "ylophonexay"

Rule #2: Words that start with a consonant should have all consonant letters up to the first vowel moved to the end of the word and then "ay" is appended. For example, the word "chair" translates into "airchay" 'Y' is considered to be vowel in this rule, so the word "xylophone" translates into "ylophonexay"

Here is my code:

import java.util.*;

public class PigLatin { public static Scanner kbd; public static void main(String[] args) { kbd = new Scanner(System.in); System.out.println("Please enter a word: "); String userWord = kbd.next(); System.out.println("Your word translated into pig latin is: "+translate(userWord)); } public static String translate(String pigLatin) { pigLatin = pigLatin.toLowerCase(); pigLatin = pigLatin.trim(); // Words that start with a vowel (A, E, I, O, U) should simply have the characters // "way" appended to the end of the word. switch(pigLatin.charAt(0)) { case 'a': case 'e': case 'i': case 'o': case 'u': return pigLatin + "way"; } // Words that start with a consonant should have all consonant letters up to the // first vowel moved to the end of the word and then "ay" is appended. //string newWord = ""; for(int i = 0; i < pigLatin.length(); i++) { switch(pigLatin.charAt(i)) { case 'a': case 'e': case 'i': case 'o': case 'u': return pigLatin.substring(i) + pigLatin.substring(0, i) + "ay"; } } return pigLatin + "ay"; } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

MFDBS 89 2nd Symposium On Mathematical Fundamentals Of Database Systems Visegrad Hungary June 26 30 1989 Proceedings

Authors: Janos Demetrovics ,Bernhard Thalheim

1989th Edition

3540512519, 978-3540512516

More Books

Students also viewed these Databases questions