Pig Latin Translator

Pig Latin Translator

Page 1 of 1

4 Replies - 2558 Views - Last Post: 05 November 2008 - 07:02 AM Rate Topic: -----

#1 Baroti  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 03-November 08

Pig Latin Translator

Post icon  Posted 03 November 2008 - 01:34 PM

Quote

Create a method that receives a String, converts the String to Pig Latin, and returns the new Pig Latinated word. There may be multiple words in your String, so you will need to have a recursive function that breaks down the String into single words and then reconstructs the sentence in Pig Latin. Here's how to translate the English word englishWord into the Pig Latin word pigLatinWord:
a. If there are no vowels in englishWord, then pigLatinWord is just englishWord + "ay". (There are ten vowels: 'a', 'e', 'i', 'o', and 'u', and their uppercase counterparts. y is not considered to be a vowel for the purposes of this assignment, i.e. my becomes myay, why becomes whyay, etc.)

b. Else, if englishWord begins with a vowel, then pigLatinWord is just englishWord + "yay".

c. Otherwise (if englishWord has a vowel in it and yet doesn't start with a vowel), then pigLatinWord is end + start + "ay", where end and start are defined as follows:
1. Let start be all of englishWord up to (but not including) its first vowel.
2. Let end be all of englishWord from its first vowel on.
3. But, if englishWord is capitalized, then capitalize end and "uncapitalize" start.


I'm totally lost on what to do on how to tackle this problem. This is what I have wrote so far:

Quote

public static String pigLatinTrans() {
String plword;
StringUtil pass = new StringUtil();
pass.str = pass.str.toLowerCase();

if (pass.str.charAt(0) == 'a' || pass.str.charAt(0) == 'e' || pass.str.charAt(0) == 'i' || pass.str.charAt(0) == 'o' || pass.str.charAt(0) == 'u' ||) {
plword = pass.str + "ay";
}
return plword;
}


Is This A Good Question/Topic? 0
  • +

Replies To: Pig Latin Translator

#2 NeoTifa  Icon User is offline

  • Whorediot
  • member icon





Reputation: 2637
  • View blog
  • Posts: 15,663
  • Joined: 24-September 08

Re: Pig Latin Translator

Posted 03 November 2008 - 01:47 PM

find the length of the word, then put the char at the beginning on the end, then add ay.

String wordlength = word.length()
then charAt(0) or something funky, and stuff idk. i did something like this too. id have to think about it, and i have to pee, so ill tell ya later
Was This Post Helpful? 0
  • +
  • -

#3 Baroti  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 03-November 08

Re: Pig Latin Translator

Posted 04 November 2008 - 01:08 PM

Anyone else who can help, I have been trying to figure this thing out for the past three days and am really lost. So Far I figured out how to do it if the first letter is a vowel, but beyond that, I am lost. Here is my code so far.

public static String pigLatinTrans() {
	
	String plword = " ";
	StringUtil pass = new StringUtil();
	StringTokenizer tokens = new StringTokenizer(pass.str);

	while (tokens.hasMoreTokens())
	{
		String temp = tokens.nextToken();
	
	if (isVowel(temp.charAt(0)))
	{
	
		plword +=temp + "yay ";
	}
	}
	
	

	return plword;	
	}
	
	private static boolean isVowel(char someChar){
	if(someChar=='a'||someChar=='e'||someChar=='i'||someChar=='o'||someChar=='u'
	   ||someChar=='A'||someChar=='E'||someChar=='I'||someChar=='O'||someChar=='U')
	{
			return true;
	}
		else return false;
	}
	
   private static boolean isNotVowel(char someChar) {
   	if(someChar!='a'||someChar!='e'||someChar!='i'||someChar!='o'||someChar!='u'
	   ||someChar!='A'||someChar!='E'||someChar!='I'||someChar!='O'||someChar!='U')
	{
			return true;
	}
		else return false;
	}
	

Was This Post Helpful? 0
  • +
  • -

#4 Onker  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 51
  • Joined: 15-July 08

Re: Pig Latin Translator

Posted 04 November 2008 - 01:55 PM

I don't have my java code handy, but if you search the forum there's at least one post by me on the topic, and I do believe I received some very good help on it as well.
Was This Post Helpful? 0
  • +
  • -

#5 Onker  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 51
  • Joined: 15-July 08

Re: Pig Latin Translator

Posted 05 November 2008 - 07:02 AM

My apologies, I just checked all my previous posts, and none of the ones in the Java forum were the pig latin translator. Although there are repeated instances of that program here.

I would be happy to help you work through the problem though. I've done it, it's not really that tough once you get the concept of everything you have to do.

I'm assuming if you're doing this that you've already dealt with Arrays and ArrayLists.

If that's the case, fantastic.

The first thing you need to do is get your input. You know how to do this in the style you like by now.

Next, you need to break the string into substrings at the whitespaces (' ')

Pass the substrings into an Array.

Iterate through the Array, and modify the substring. If you have "that" you need to test to see if the first letter is a vowel, act on that substring accordingly.

The easiest way to work it from there, in my opinion, is to build the result string as you pass through the array. for instance:
result = result + " " + alteredSubstring);



Of course, there are several steps left in there for you to do, detecting if the first letter is a vowel, etc. Hopefully that sets you on the right path.

If you're still having problems, post your updated code and I'll take a gander at it.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1