/* Tom DeDonno page 11.5, 740

   Implements recursion until user enters correct input, a positive number.

   Translated showCountDown into recursive routine
 */

public class CountDown
{
    private int count;

    public static void main(String[] args)
    {
         CountDown countDowner = new CountDown();
         countDowner.getCount();
         countDowner.showCountDown();
         countDowner.showCountDown2( countDowner.count );
    }

    public void getCount()
    {
        System.out.println("Enter a positive number:");
        count = SavitchIn.readLineInt();
        if (count <= 0)
        {
            System.out.println("Input must be positive.");
            System.out.println("Try again.");
            getCount();//start over
        }
    }

    public void showCountDown()
    {
        int left;
        System.out.println("Counting down:");
        for (left = count; left >= 0; left--)
            System.out.print(left + ", ");
        System.out.println("Blast Off!");
     }
    
    private boolean firstTime = true;
    public void showCountDown2( int left )
    {
    if( firstTime ) { firstTime = false; System.out.println( "Counting down:" ); }
    System.out.print( left + "," );
    if( left > 1 ) showCountDown2( left-1 );
    else { 
      System.out.println( "Blast Off!" );
      firstTime = false;
    }
  }
  
}