import java.io.PrintWriter;
import java.util.Scanner;

/**********************************************************************
 * Class purpose: Show students the flush() method of the PrintWriter 
 * class & teach them how to correct errors concerning this method.
 *
 * @author David Petri
 * @version V1 1/22/07
 * Lab 4
 * Section 2
 *********************************************************************/
public class IO_petridw_Rooter
{

 /******************************************************************
   * Method purpose: Main method for a program that uses the PrintWriter
	* class to output the square root of a number to the user.
   *
   * @param args unused
    *****************************************************************/
    public static void main(String[] args)
    {
       double          value, result;       
       PrintWriter     screen;       
       Scanner         keyboard;
       
       screen   = new PrintWriter(System.out);       
       keyboard = new Scanner(System.in);

		 //Prompt for the first input
       screen.println("Enter a number: ");    
       screen.flush();
       
		 //As long as something has been entered through the Standard input
		 //Scanner, continue to receive input.
       while (keyboard.hasNext())
       {
		 	 //Store the value that was last entered
          value = keyboard.nextDouble();
			 //Calculate the square root of that value
          result = Math.sqrt(value);
          
			 //Print the result & ask for the next input
          screen.printf("The square root of " + value + " is " + result);
          screen.flush();
          
          screen.println("Enter a number: ");       
        	 screen.flush();
       }
		 
		 //Print the normal ending message
       screen.println("Done.\n");       
       screen.flush();
    }
    
}
