import java.util.Scanner;
/*************************************************************************
 * Bottles of Pop - Plays the drinking song, Bottles of Pop
 *
 * @author Nancy Harris
 * @version V1
 ************************************************************************/
    public class BottlesOfPop
   {
   /*********************************************************************
    * main method - sings the song
    *
    * @param args Command line arguments
    ********************************************************************/
       public static void main (String args[])
      {
         int bottles;
         int stanzas;
        
         boolean good;
        
         Scanner keyboard;
        
         keyboard = new Scanner (System.in);
        
        // read in the number of bottles and stanzas
            // read in bottles & validate
         good = false;
			bottles = -1; // make compiler happy
         do 
         {
            System.out.print("How many bottles? ");
                
            if (keyboard.hasNextInt())
            {
               bottles = keyboard.nextInt();
               good = validateBottles(bottles);
            }
            else
            {
               System.out.println("You entered " + keyboard.nextLine() + ".");
               System.out.println("Try again.");
            }
         } while (!good);
      		
            // read in stanzas & validate
         good = false;
			stanzas = -1; // make compiler happy
         do 
         {
            System.out.print("How many stanzas? ");
                
            if (keyboard.hasNextInt())
            {
               stanzas = keyboard.nextInt();
               good = validateStanzas(bottles, stanzas);
            }
            else
            {
               System.out.println("You entered " + keyboard.nextLine() + ".");
               System.out.println("Try again.");
            }
         } while (!good);
      
        // sing the song
         while (stanzas > 0)
         {
            System.out.println(bottles + " bottles of pop on the wall.");
            System.out.println(bottles + " bottles of pop.");
            System.out.println("If one of those bottles should happen to fall,");
            bottles --;
            System.out.println(bottles + " bottles of pop on the wall.");
            stanzas--;
         }
      }
		/*********************************************************************
		 * validateBottles makes sure the bottles are between 0 and 100
		 *
		 * @param bottles The number of bottles entered
		 * @return true if the number is okay, false otherwise
		 ********************************************************************/
		 public static boolean validateStanzas(int bottles, int stanzas)
		 {
		 	boolean result;
			result = false;
		 	if (bottles < stanzas)
				System.out.println(stanzas + " is greater than bottles.\nTry again.");
			else
				result = true;
			return result;
		}
		/*********************************************************************
		 * validateBottles makes sure the bottles are between 0 and 100
		 *
		 * @param bottles The number of bottles entered
		 * @return true if the number is okay, false otherwise
		 ********************************************************************/
		 public static boolean validateBottles(int bottles)
		 {
		 	boolean result;
			result = false;
		 	if (bottles < 0 || bottles > 100)
				System.out.println(bottles + " is not between 0 and 100.\nTry again.");
			else
				result = true;
			return result;
		}
	
   }	
