// NeedsMethods.java

// This class needs some methods!
public class NeedsMethods
{ 
   public static void main(String args[])
   {
      String instructor = "Kiri Wagstaff";
      String sentence = "The quick brown fox jumps over the lazy dog.";

      System.out.println("This program analyzes vowel occurrence in different strings.");

      // Count the number of words in instructor.
      // Loop through the string and examine each character.
      // If it is whitespace, then we found the beginning of a new word;
      // increment the word counter.
      int numWords = 1; // assume at least one word
      for (int i = 0; i < instructor.length(); i++)
      {
         char letter = instructor.charAt(i);
				 // isWhitespace returns true if the input character
				 // is a whitespace character, otherwise false
				 if (Character.isWhitespace(letter))
	 			 {
	     			numWords++;
	 			 }
      }

      // Count how many vowels are in instructor
      // Loop through the string and examine each character.
      // If it is a vowel, increment the vowel counter.
      int numVowels = 0;
      for (int i = 0; i < instructor.length(); i++)
      {
	  		char letter = instructor.charAt(i);
	  		if (letter == 'a' || letter == 'e' || letter == 'i' ||
	      		letter == 'o' || letter == 'u')
	  		{
	      	numVowels++;
	  		}
      }

      System.out.println("\"" + instructor + "\"" + " has " +
			 										numVowels + " vowels.");
      System.out.println("This is an average of " +
			 										numVowels / (double) numWords +
			 										" vowels per word.\n");

      System.out.println("Now let's try it with a longer string.\n");

      // Count how many vowels are in the sentence
      // Loop through the string and examine each character.
      // If it is a vowel, increment the vowel counter.
      numVowels = 0;
      for (int i = 0; i < sentence.length(); i++)
      {
			  char letter = sentence.charAt(i);
	  		if (letter == 'a' || letter == 'e' || letter == 'i' ||
	      		letter == 'o' || letter == 'u')
	  		{
	      	numVowels++;
	  		}
      }

      // Count the number of words in the sentence.
      // Loop through the string and examine each character.
      // If it is whitespace, then we found the beginning of a new word;
      // increment the word counter.
      numWords = 1; // assume at least one word
      for (int i = 0; i < sentence.length(); i++)
      {
	  		char letter = sentence.charAt(i);
	  		// isWhitespace returns true if the input character
	  		// is a whitespace character, otherwise false
	  		if (Character.isWhitespace(letter))
	  		{
	      	numWords++;
	  		}
      }

      System.out.println("\"" + sentence +  "\"" + " has " +
												 numVowels + " vowels.");
      System.out.println("This is an average of " +
			 										numVowels / (double) numWords +
			 										" vowels per word.\n");

   }
}
