Pig Latin translator

my code is working but I am trying to tell it to look for a vowel on t

Page 1 of 1

5 Replies - 1495 Views - Last Post: 05 June 2009 - 06:42 AM Rate Topic: -----

#1 gmillerlight   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 27
  • Joined: 30-April 09

Pig Latin translator

Post icon  Posted 04 June 2009 - 06:52 PM

package translationapplication;

/**
 *
 * @author 
 */
public class PigLatinTranslator
{
	public String translate (String wordEnglish)
	{
		String vowels = "a,e,i,o,u,A,E,I,O,U";
		String translate = wordEnglish;
		
		if (wordEnglish.contains(vowels))
	   {
			convertedWord = wordEnglish.substring(0) + "ay";
			return convertedWord;
		}

				  else
		
		convertedWord = wordEnglish.substring(1)+ wordEnglish.charAt(0) + "ay";
		return convertedWord;
	}
	private String convertedWord;

	public String getConvertedWord()
	{
		return convertedWord;
	}

	/**
	 * @param convertedWord the convertedWord to set
	 */
	public void setConvertedWord(String convertedWord)
	{
		this.convertedWord = convertedWord;
	}

}
   



package translationapplication;
import java.util.Scanner;
/**
 *
 * @author Georgia
 */
public class translationApplication
{

	/**
	 * @param args the command line arguments
	 */
	public static void main(String[] args)
	{
	  // variable declaration
		String wordEnglish;
		String wordPigLatin;
		String done = "Y";
		int word;
		Scanner input = new Scanner(System.in);
		PigLatinTranslator myTranslator = new PigLatinTranslator();

		while (!done.equals ("N"))
		{

			System.out.println("Enter a word to be translated: ");
			wordEnglish = input.nextLine();
		   
			wordPigLatin = myTranslator.translate(wordEnglish);

			System.out.println(wordEnglish + " translates to " + wordPigLatin);

			System.out.print("Do you wish to translate another word?(Y/N)");
			done = input.nextLine();
		}

		System.out.println("Thanks you for translating with us.");
			
	
	}

}



Is This A Good Question/Topic? 0
  • +

Replies To: Pig Latin translator

#2 Hiram   User is offline

  • D.I.C Head

Reputation: 69
  • View blog
  • Posts: 203
  • Joined: 02-June 09

Re: Pig Latin translator

Posted 04 June 2009 - 06:58 PM

	String vowels = "a,e,i,o,u,A,E,I,O,U";
	String translate = wordEnglish;

	if (wordEnglish.contains(vowels))



Try looking at this code, and at what contains does.

For what you're wanting to do, vowels should be an array, for a start.
Was This Post Helpful? 0
  • +
  • -

#3 pbl   User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8381
  • View blog
  • Posts: 31,956
  • Joined: 06-March 08

Re: Pig Latin translator

Posted 04 June 2009 - 09:00 PM

Please do not put your question in the topic title... it gets truncated
Was This Post Helpful? 0
  • +
  • -

#4 gmillerlight   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 27
  • Joined: 30-April 09

Re: Pig Latin translator

Posted 05 June 2009 - 04:44 AM

How do I get it to look at the first letter of the word and see if it is a vowel? If is just add ay, if it isn't (this part works its not working for vowels) move first letter to end of word and add ay. I need it to look for vowels.
package translationapplication;

/**
 *
 * @author 
 */
public class PigLatinTranslator
{
	public String translate (String wordEnglish)
	{
		String vowels = "a,e,i,o,u,A,E,I,O,U";
		String translate = wordEnglish;
		
		if (firstLetter.contains(vowels))	 
							   {
			convertedWord = wordEnglish.substring(0) + "ay";
			return convertedWord;
		}

				  else
		
		convertedWord = wordEnglish.substring(1)+ wordEnglish.charAt(0) + "ay";
		return convertedWord;
	}
	private String convertedWord;

	public String getConvertedWord()
	{
		return convertedWord;
	}

	/**
	 * @param convertedWord the convertedWord to set
	 */
	public void setConvertedWord(String convertedWord)
	{
		this.convertedWord = convertedWord;
	}

}
   



package translationapplication;
import java.util.Scanner;
/**
 *
 * @author 
 */
public class translationApplication
{

	/**
	 * @param args the command line arguments
	 */
	public static void main(String[] args)
	{
	  // variable declaration
		String wordEnglish;
		String wordPigLatin;
		String done = "Y";
		int word;
		Scanner input = new Scanner(System.in);
		PigLatinTranslator myTranslator = new PigLatinTranslator();

		while (!done.equals ("N"))
		{

			System.out.println("Enter a word to be translated: ");
			wordEnglish = input.nextLine();
		   
			wordPigLatin = myTranslator.translate(wordEnglish);

			System.out.println(wordEnglish + " translates to " + wordPigLatin);

			System.out.print("Do you wish to translate another word?(Y/N)");
			done = input.nextLine();
		}

		System.out.println("Thanks you for translating with us.");
			
	
	}

}


[/quote]
Was This Post Helpful? 0
  • +
  • -

#5 computerfox   User is offline

  • straight vegetarian kid

Reputation: 50
  • View blog
  • Posts: 3,772
  • Joined: 29-January 09

Re: Pig Latin translator

Posted 05 June 2009 - 05:49 AM

hope this helps
Was This Post Helpful? 0
  • +
  • -

#6 NeoTifa   User is offline

  • NeoTifa Codebreaker, the Scourge of Devtester
  • member icon





Reputation: 4933
  • View blog
  • Posts: 20,259
  • Joined: 24-September 08

Re: Pig Latin translator

Posted 05 June 2009 - 06:42 AM

If(wordOfEnglish.charAt(0) == 'a' || (goes through all vowels)) {
just add "ay"
}

else {
make 2 substings, one with the first letter(firstLetter), and the other with the remaining letters(restOfWord). Print them out and put restOfWord + firstLetter + "ay"
}

Hope that helped a little.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1