Hey, Iam trying to write a java application that acts as a one-word Pig Latin translator.
The program should:

1.ask the user to enter a word

2.convert the entered word into proper Pig Latin translation, (I have to use a method named translate to get the Pig Latin translation of the input word)

3.print the translated word on the screen

And it has to follow these rules:

•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"

And I 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.

Example

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


I have no clue where to start. Any help would be helpfully.

Thanks

1. You need to get the word from the user.
2. Create a method where you will pass this word.
3. In your method check if the 1st char is a bowel and then follow the rules.

Try to coding 1st then if you encounter any errors or youre stucked then you can post your questions (",)

A bowel? As in intestines (I.E. your "guts")? ;-)

oh hehehe (",) sorry about that. I mean 'Vowel' ;-)

You need a method which accepts a String as the parameter

public static String translate(String word)
{
  // TODO: Implement according to guidelines.
}

Now, lets think about the first case. You need to check and see if the first character of the word is a vowel (or a bowel according to Eric :)). You can use an if statement for that

if(first character is a vowel)
{
  // TODO: Follow PigLatin's rule #1 
}

The second and third rule are in the same fashion - check that you are in the rule's guidelines, and if you are, change the word String to follow the rules.

You can find helpful methods to help you manipulate Strings in the Java String API - such as the charAt(int index) method.

Good luck!

Do I need a while loop also?

If you need the user to enter more than one word, then perhaps you do need a loop. What do the rules say about when to stop asking the user for words to translate?

Closing thread, please follow discussion here

@DallasFan3
1. Do not post the same question multiple times
2. Do wrap your programming code blocks within [code] ... [/code] tags

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.