/**
 *  EggyPeggy Class
 *
 * <p>
 *  An EggyPeggy object plays the word game Eggy-Peggy. Pass the original 
 *  string to the convert method, and it will return an Eggy-Peggy string,
 *  a string where all the vowels are preceded by the word 'egg'. You can
 *  change the default prefix word 'egg' to any word you like by calling
 *  the SetPrefixWord method.
 */
class EggyPeggy  //Step 2: Implement 'setPrefixWord' and 'convert'
{
//--------------------------------
//    Data Members
//--------------------------------
    
    /**
     * The name of the file where an AddressBook is stored
     */
    private static final String DEFAULT_PREFIX = "egg";
   
    /**
     * The text to be added in front of all vowels
     */
    private String prefix;

//--------------------------------
//    Constructors
//--------------------------------
    
    /**
     * Default constructor. 
     */
    public EggyPeggy( )
    {
        this(DEFAULT_PREFIX);
    }
   
    /**
     * Constructs an EggyPeggy object with the replacement
     * prefix text is set to the parameter value.
     *
     * @param prefix the string to put in front of any vowel
     */
    public EggyPeggy( String prefix )
    {
        this.prefix = prefix;
    }


//-------------------------------------------------
//      Public Methods:
// 
//          String    covert          (   String     )
//          void      setPrefixWord   (   String     )
//------------------------------------------------
   
   /**
    * Converts an argument string to an Eggy-Peggy string.
    * Data member 'prefix' is the word placed in front of
    * all vowels in the original string.    
    *
    * @param originalSentence the original sentence before 
    *                         the conversion
    *
    * @return the converted sentence
    *
    */
    public String convert(String originalSentence)
   {
      int           numberOfCharacters;
      char          letter;
      StringBuffer  encryptedSentence;
      
      encryptedSentence = new StringBuffer("");
      numberOfCharacters = originalSentence.length();
      
      for (int index = 0; index < numberOfCharacters; index++) {
         //get the next letter
         letter = originalSentence.charAt(index);

         if ( isVowel(letter) ) {
            //add the prefix string and then the vowel
            //to encryptedSentence
            encryptedSentence.append(prefix + letter);  
         }
         else {
            //add the letter to encryptedSentence
            encryptedSentence.append(letter);
         }
      }
      
      return encryptedSentence.toString();
   }

   /**
    * Sets the prefix to the passed argument.
    *
    * @param prefix the new prefix
    *
    */
   public void setPrefixWord(String prefix)
   {
      this.prefix = prefix;
   }

  
//-------------------------------------------------
//      Private Methods:
// 
//          boolean    isVowel     (   char     )
//          
//------------------------------------------------
   
   /**
    * Determines if the argument character is a vowel    
    *
    * @param letter the character to check whether it
    *               is a vowel
    *
    * @return true if it is a vowel; otherwise false
    *
    */
   private boolean isVowel(char letter)
   {
      boolean result = false;

      if ( letter == 'A' || letter == 'a' ||
           letter == 'E' || letter == 'e' ||
           letter == 'I' || letter == 'i' ||
           letter == 'O' || letter == 'o' ||
           letter == 'U' || letter == 'u'    ) {
      
         result = true;
      }
      
      return result;
   }
}
