   import java.util.Scanner;

/** PopSong sings the bottles of pop song.
 *
 * @author Nancy Harris
 * @version V1 10/19/2008
 ******************************************/
    public class PopSong
   {
       public static void main(String args[])
      {
         Scanner kb;
         int bottles;
         int verses;
         int badValue;
         String bottles1;
         String bottles2;
      
         kb = new Scanner(System.in);
         
      	// set up to print bottle or bottles
      	bottles1 = "bottles";
      	bottles2 = "bottles"; 
      	
      // get number of bottles
         bottles = -100;
      
         System.out.print("Enter the number of bottles: ");
         while (bottles < 0)
         {
            if (kb.hasNextInt())
            {
               bottles = kb.nextInt();
            
               if (bottles > 100 || bottles < 0)
               {
                  System.out.println("You must enter a number between " + 
                     "0 and 100. Try again.");
                  bottles = -100;
               }
            }
            else
            {
               System.out.println("You entered " + kb.nextLine() + "." + 
                  "This is not a number. Try again.");
            }
         } // end while
      
      // get number of verses
         verses = -100;
         System.out.print("Enter the number of verses: ");
         while (verses < 0)
         {
            if (kb.hasNextInt())
            {
               verses = kb.nextInt();
            
               if (verses > bottles || verses < 0)
               {
                  System.out.println("You must enter a number between " + 
                     "0 and " + bottles + ". Try again.");
                  verses = -100;
               }
            }
            else
            {
               System.out.println("You entered " + kb.nextLine() + "." + 
                  "This is not a number. Try again.");
            }
         } // end while
        System.out.println();
        
      // display the song
         for (int ii = bottles; ii > bottles - verses; ii--)
         {
         	if (ii > 2)
         	{
         		bottles1 = " bottles";
         		bottles2 = " bottles";
         	}
         	else if (ii == 2)
         	{
         		bottles1 = " bottles";
         		bottles2 = " bottle";
         	}
         	else 
         	{
         		bottles1 = " bottle";
         		bottles2 = " bottles";
         	}	
            
            System.out.println(ii + bottles1 + " of pop on the wall.");
            System.out.println(ii + bottles1 + " of pop.");
            System.out.println("If one of those bottles should happen to fall,");
            System.out.println((ii - 1) + bottles2 + " of pop on the wall.\n");
    			
				kb.nextLine();    
		   }
      }
   }