Results 1 to 2 of 2
  1. #1
    kulafo is offline Member
    Join Date
    Mar 2013
    Posts
    1
    Rep Power
    0

    Default calling the method

    so i got this program where if i put a sentece it should translate it to piglatin
    the rule is
    if the first letter of a word is vowel it add "way"
    and if its not it will find the first vowel of the word the the letters before it will be put in the end and add "ay", but then
    i got this problem in my main method
    im trying to call a method and translate the inputted sentence but then it does not do anything


    Java Code:
    import java.util.StringTokenizer;
    public class PIGLATIN
    {
    
        public static void main(String[] args) {
           System.out.println("Enter Sentece: ");
            PIGLATIN tokenizer = new PIGLATIN(); // create a new instance of Tokenizer
            tokenizer.translate(null);// call the public translate method
    
            }
    
           public String translate (String sentence)
           {
              String result = "";
              sentence = sentence.toLowerCase();
              StringTokenizer tokenizer = new StringTokenizer (sentence);
              while (tokenizer.hasMoreTokens())
              {
                 result += translateWord (tokenizer.nextToken());
                 result += " ";
              }
              return result;
           }
    
           private String translateWord (String word)
           {
              String result = "";
              if (beginsWithVowel(word))
                 result = word + "way";
              else
                 if (beginsWithBlend(word))
                    result = word.substring(2) + word.substring(0,2) + "ay";
                 else
                    result = word.substring(1) + word.charAt(0) + "ay";
              return result;
           }
           private boolean beginsWithVowel (String word)
           {
              String vowels = "aeiou";
              char letter = word.charAt(0);
              return (vowels.indexOf(letter) != -1);
           }
           private boolean beginsWithBlend (String word)
           {
              return ( word.startsWith ("qu")  );
           }
    
        }

  2. #2
    jim829 is online now Senior Member
    Join Date
    Jan 2013
    Location
    United States
    Posts
    3,376
    Rep Power
    5

    Default Re: calling the method

    For starters, you have prompted for a sentence but never entered one. And you are passing null to your translate method.

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

Similar Threads

  1. Calling another method help?
    By xxdave in forum New To Java
    Replies: 3
    Last Post: 11-24-2011, 02:45 AM
  2. Thread problem, calling method in run method
    By majk in forum Threads and Synchronization
    Replies: 4
    Last Post: 09-27-2010, 11:40 AM
  3. Calling The main method from another method
    By SwissR in forum New To Java
    Replies: 3
    Last Post: 07-27-2010, 11:03 AM
  4. calling method from main method
    By bob_bee in forum New To Java
    Replies: 4
    Last Post: 10-02-2009, 05:30 PM
  5. Replies: 29
    Last Post: 09-25-2008, 07:55 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •