import java.util.Scanner;

/**
 * This class contains numerous static methods for manipulating Strings.
 * 
 * @author Dave Reed
 * @version 4/10/2010
 */
public class StringUtils {
    /**
     * Reverses a string.
     *   @param str the string to be reversed
     *   @return a copy of str with the order of the characters reversed
     */
    public static String reverse(String str) {
        String copy = "";
        for (int i = 0; i < str.length(); i++) {
            copy = str.charAt(i) + copy;
        }
        return copy;
    }
    
    /**
     * Removes all non-letters from a string.
     *   @param str the string to be stripped
     *   @return a copy of str with all non-letters removed
     */
    public static String stripNonLetters(String str) {
        String copy = "";
        for (int i = 0; i < str.length(); i++) {
            if (Character.isLetter(str.charAt(i))) {
                copy += str.charAt(i);
            }
        }
        return copy;    
    }

    /**
     * Determines whether a string is a palindrome.
     *   @param str the string to be tested
     *   @return true if the string is a palindrome; else, false
     */     
    public static boolean isPalindrome(String str) {
        str = str.toLowerCase();
        str = StringUtils.stripNonLetters(str);
        
        String reverseStr = StringUtils.reverse(str);
        
        return (str.equals(reverseStr));
    }
    
    ///////////////////////////////////////////////////////////////////////

    /**
     * Finds the first occurrence of a vowel in a string.
     *   @param str the string to be searched
     *   @return the index of the first occurrence of a vowel from seq
     */
     public static int findVowel(String str) {
        str = str.toLowerCase();

        String vowels = "aeiou";        
        for (int i = 0; i < str.length(); i++) {
            char nextChar = str.charAt(i);
            if (vowels.indexOf(nextChar) != -1) {
                return i;
            }
        }
        return -1;
    }
 
    /**
     * Translates a string into Pig Latin
     *   @param str the string to be translated
     *   @return a copy of str translated into Pig Latin
     */     
    public static String pigLatin(String str) {  
        int firstVowel = StringUtils.findVowel(str);
        
        if (firstVowel <= 0) {
            return str + "way";
        }
        else {
            return str.substring(firstVowel, str.length()) + 
                   str.substring(0,firstVowel) + "ay";
        }
    }
}
   
