Question: (I need assistance in coreecting my code that is intended to translate an english word into pig latin.) import java.util.*; public class PigLatin { public

(I need assistance in coreecting my code that is intended to translate an english word into pig latin.)

import java.util.*;

public class PigLatin {

public static Scanner kbd;

public static void main(String[] args) {

kbd = new Scanner(System.in); System.out.println("Enter a word: "); String word = kbd.next(); System.out.println("Your word translated into pig latin is: "+translate(word)); kbd.close(); } public static String translate (String s) { if (startsWithVowel(s)) { return s + "way"; } else { String newStr = ""; if (s.length() > 1) { if (s.charAt(1) =='h') { newStr = s.substring(2); newStr = newStr + s.substring(0,2) + "ay"; } else { newStr = s.substring(1); newStr = newStr + s.charAt(0) + "ay"; } return newStr; } else { return s; } } } public static boolean startsWithVowel(String s) { return s.startsWith("a") || s.startsWith("e") || s.startsWith("i") || s.startsWith("o") || s.startsWith("u"); } }

(Here is what I have so far and below are the original instructions for the project.)

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

The following is an example of what your MIGHT see on the screen when your program runs. The exact output depends on the values that the user types in while the program runs. The user's values are shown below in italics:

Please enter a word: pig Your word translated into Pig Latin is: igpay

Here's another example:

Please enter a word: latin Your word translated into Pig Latin is: atinlay

The rules for pig latin translation are as follows:

Rule #1: Words that start with a vowel (A, E, I, O, U) should simply have the characters "way" appended to the end of the word. For example, the word "apple" translates into "appleway" 'Y' is not counted as a vowel for this rule.

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" It is possible that the word may not contain any vowels at all. In this case, following rule #2, you would simply append "ay" to the end of the word. For example, the word "crwth" translates into "crwthay"

Rule #3: When "Y" is the first letter of the word, the word should follow Rule #2. As an example, the word "yellow" translates into "ellowyay"

Program Requirements

The user should enter all lowercase letters. If the user enters any uppercase letters, you should convert to all lowercase before proceeding. Additionally, also remove any spaces that the user may enter at the beginning or end of the word. There are methods in the String class to do both of these tasks.

The main program should only do three basic things:

Get the input from the user

Use a method named translate to get the Pig Latin translation of the input word

Print the result to the screen

The main program is NOT allowed to do any String processing that is the job of the translatemethod. The main program should only do the three things listed above.

You must write and use a method called translate. This method should NOT get any values from the user/keyboard that job should be done by the main program. This method should be sent a String value from the main program. This string is the word which should be translated into Pig Latin. The method, then, should create a new string (you will need a local variable to hold this string temporarily). This new string will be the translation of the original word. Finally, this method will need to send the new string back to the main program so that the main program can print the final result.

The translate method is NOT allowed to print anything to the screen.

Declare the keyboard object as a class (global) variable as discussed in our class example. You are NOT allowed to use any other class (global) variables in this program. All other variables must be declared as local.

The following is a link to an online Pig Latin translator that you can use to ensure that your program is performing correctly with words that you type into it: http://users.snowcrest.net/donnelly/piglatin.html

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 Databases Questions!