import java.util.Random;
/** 
* 
*  This class generates words in the language of an alien race 
*  Problem comes from Lewis and Loftus Chapter 11 - #11.7
*  Version 1.0 has diagnostic output
*
*  @author Elizabeth Adams
*  @version 1.1
*/
public class P5
{   

   
  private String blurb;
  private Random myRandom;
     

    /**
	 * 
	 * Explicit constructor
	 *
	 */
    public P5()
	 { 
	    myRandom = new Random(); 
	    blurb = "x";
	    this.generateBlurb();
	 }// end constructor

     /**
	  *  this method does the work of generating legal Blurbs
	  * 
	  */  
	  private void generateBlurb()
	  {   
         int qZorD;
			int numberYs;

         numberYs = myRandom.nextInt(5);
         this.blurb = this.blurb +  this.whoozit(numberYs);
			
         qZorD = myRandom.nextInt(2);
         this.blurb = this.blurb + this.whatzit(qZorD);
      
		   numberYs = myRandom.nextInt(5);
         this.blurb = this.blurb + "x" + this.whoozit(numberYs);      
      } // end generateBlurb
 	
	 
    /**
	 *  constructs a Whatzit which is a 'q' followed by
	 *  either a 'z' or a 'd' followed by a whoozit
	 *
	 *  @param 0 if qd, 1 if qz
	 *  @return qd or qz
	 * 
	 */
	 private String whatzit (int zd)
	 {
	     String  answer;
	     if (zd == 0)
		     answer = "qd";
		  else
		     answer = "qz";
		  return answer;
	 }
	 
	 /**
	 *  This recursive method generates a whoozit which is 
	 *  an 'x' followed by string of 0 or more 'y's
	 *
	 *  @param the number of 'y's in the string
	 *  @return a string of x followed by 0 or more 'y's
	 *
	 */
	 private String whoozit(int numberYs)
	 {
	    String answer;
		 
	    answer = "";
	    answer = answer + wise(numberYs);
		 return  answer;
	 }	 
	 
	 /**
	 *  retursive method returns a string of 0 or more 'y's
	 *
	 *  @param number of 'y's to be generated
	 *  @return string of 0 or more 'y's
	 *
	 */
	 private String wise (int howManyMore)
	 {	     		  		  
	     if (howManyMore == 0)
		     return "";
		  else
		     return "y" + wise(howManyMore-1);
	 } // end wise

    /**
	 *  this method returns a Blurb to the calling program
	 * 
	 */
    public String getBlurb ()
	 {
	    return blurb;
	 }

}// end P5	 