Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: having problems with my pig latin translator (the translating portion)

  1. #1
    Junior Member
    Join Date
    Jan 2011
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Unhappy having problems with my pig latin translator (the translating portion)

    import java.util.*;
     
    public class PigLatinTranslator
    {
    	public String translate (String sentence)
    	{
    		String result = "";
     
    		sentence = sentence.toLowerCase();
    		Scanner scan = new Scanner (sentence);
     
     
    		while (scan.hasNext())
    	{
    		result += translateWord (scan.next());
    		result += " ";
    	}
     
    	return result;
    }
     
     
    public boolean beginsWithVowel (String word)
    {
    	String vowels = "aeiou";
     
    	char letter = word.charAt(0);
     
    	return (vowels.indexOf(letter) != -1);
    }
     
     
    public String translateWord (String word)
    {
    	String result = "";
     
     
    	if (beginsWithVowel)               [B][U]// says "cannot find symbol - variable beginswithVowel[/U][/B]
    		result = word + "yay";
    	else
    	   if (beginsWithBlend (word))
    	       result = word.substring(2) + word.substring(0,2) + "ay";
    	    else
    		result = word.substring(1) + word.charAt(0) + "ay";
     
     
    	return result;
    }
     
     
     
    public boolean beginswithBlend (String word)
    {
    	return ( word.startsWith ("bl") || word.startsWith ("sc") ||
    		 word.startsWith ("br") || word.startsWith ("sh") ||
    		 word.startsWith ("ch") || word.startsWith ("sk") ||
    		 word.startsWith ("cl") || word.startsWith ("sl") ||
    		 word.startsWith ("cr") || word.startsWith ("sn") ||
    		 word.startsWith ("dr") || word.startsWith ("sm") ||
    		 word.startsWith ("dw") || word.startsWith ("sp") ||
    		 word.startsWith ("fl") || word.startsWith ("sq") ||
    		 word.startsWith ("fr") || word.startsWith ("st") ||
    		 word.startsWith ("gl") || word.startsWith ("sw") ||
    		 word.startsWith ("gr") || word.startsWith ("th") ||
    		 word.startsWith ("kl") || word.startsWith ("tr") ||
    		 word.startsWith ("ph") || word.startsWith ("tw") ||
    		 word.startsWith ("pl") || word.startsWith ("wh") ||
    		 word.startsWith ("pr") || word.startsWith ("wr") );
    	}
    }
    Last edited by helloworld922; January 12th, 2011 at 03:34 PM.


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,307
    Thanks
    181
    Thanked 824 Times in 767 Posts
    Blog Entries
    5

    Default Re: having problems with my pig latin translator (the translating portion)

    Please read the Welcome Announcement, as this provides instructions for how to format your code to make it much more readable.

    beginsWithVowel cannot be found because it is never defined, you must define the variable first (in this case as a boolean).

  3. #3
    Junior Member
    Join Date
    Jan 2011
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: having problems with my pig latin translator (the translating portion)

    Thank you, but i'm not sure where i should define this as a boolean, & im not too sure how. (Yes i'm a noob).

  4. #4
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,307
    Thanks
    181
    Thanked 824 Times in 767 Posts
    Blog Entries
    5

    Default Re: having problems with my pig latin translator (the translating portion)

    Recommended reading: Java Variables and Methods

    After a closer look, it seems you wish to call the method beginsWithVowel ?

    if ( beginsWithVowel (word) )//
     
    or
     
    boolean beginsWithVowel  = beginsWithVowel (word);

  5. The Following User Says Thank You to copeg For This Useful Post:

    WontonSoup (January 12th, 2011)

Similar Threads

  1. Making a portion of JTextArea uneditable
    By nik_meback in forum AWT / Java Swing
    Replies: 2
    Last Post: December 15th, 2010, 10:07 AM
  2. Latin square logic
    By Deprogrammer in forum What's Wrong With My Code?
    Replies: 2
    Last Post: November 21st, 2010, 08:38 AM
  3. Help with Pig Latin Translator...
    By jchan in forum AWT / Java Swing
    Replies: 3
    Last Post: September 28th, 2009, 02:54 PM
  4. How to Read a Portion of a File in Java?
    By jazz2k8 in forum File I/O & Other I/O Streams
    Replies: 3
    Last Post: July 7th, 2009, 04:16 PM
  5. Pig Latin Translator
    By BMN901 in forum File I/O & Other I/O Streams
    Replies: 5
    Last Post: June 17th, 2009, 03:31 AM

Tags for this Thread