package strings;

public class WordUtility {
  private static String vowels = "AEIOUaeiou";

  //returns true if the character c is a vowel
  // and false otherwise.
  public static boolean isVowel(char c) {
    int index = vowels.indexOf(c);
    return index != -1;
  }

  //returns the position of the first vowel in s
  // or -1 if s doesn't contain any vowels.
  public static int firstVowelPosition(String s) {
    for (int i = 0; i < s.length(); i++)
      if (isVowel(s.charAt(i)))
        return i;
    return -1;
  }

  // returns the position of the first blank character in s
  //     or -1 if s does not contain blanks.
  public static int firstBlank(String s) {
    return s.indexOf(' ');
  }

// returns the first occurrence of c in s or -1 .
  public static int firstOccurrence(String s, char c) {
    for (int i = 0; i < s.length(); i++)
      if (c == s.charAt(i))
        return i;
    return -1;
  }

//returns the position of the first nonblank character in s or -1
// if s only contains blanks.
  public static int firstNonBlank(String s) {
    for (int i = 0; i < s.length(); i++)
    if (s.charAt(i) != ' ')
      return i;
  return -1;
  }

  // returns the position of the first character in s that is not a vowel
  //    or -1 if s contains all vowels.
  public static int firstNonVowel(String s) {
    for (int i = 0; i < s.length(); i++)
     if (!isVowel(s.charAt(i)))
       return i;
   return -1;
  }

// returns the number of vowels in s
  public static int numberVowels(String s) {
    int sum = 0;
    for (int i = 0; i < s.length(); i++)
     if (isVowel(s.charAt(i)))
       sum++;
   return sum;
  }

// returns the number of non vowel characters in s
  public static int numberNonVowels(String s) {
    return s.length() - numberVowels(s);
  }

}

