Quantcast
Channel: Programmers Heaven Forums RSS Feed
Viewing all articles
Browse latest Browse all 2703

CALLING A METHOD

$
0
0
please someone help me how to the method in order to translate the entered sentence but i can't call the method...so can anyone help?


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();// 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")  );
       }
       
    }


Viewing all articles
Browse latest Browse all 2703

Trending Articles