import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.util.Scanner;

/**
 * Rooter.java - this program is to use PrintWriter and Scanner
 * It takes in an input string of doubles and prints the square
 * root of each one.  It then will wait for more input.  Use a
 * Ctrl-Z to stop the input loop and the program will exit normally
 * 
 * @author Andrew Herrington
 * @date 1/22/06
 * @lab Lab4
 * @section 1
 */

public class IO_herrinaj_Rooter
{
	
	/** ========================================================
	* 
	*  main method - Takes input of doubles and prints their
	*  square roots.  Uses PrintWriter and Scanner.
	*              
	*  @param args   command line arguments not used in this 
	*  		application
	*/
    public static void main(String[] args)
    {
       double          value, result;       
       PrintWriter     screen;       
       Scanner         keyboard;
       
       screen   = new PrintWriter(System.out, true);       
       
       keyboard = new Scanner(System.in);
       
       screen.println();
      
       screen.println("Enter a number: ");    
       
       try
       {
       //loop until Ctrl-Z
    	   while (keyboard.hasNext())
    	   {
    		   value = keyboard.nextDouble();
    		   result = Math.sqrt(value);

    		   screen.printf("The square root of " + value + " is " + result);
    		   screen.flush();
          
    		   screen.println("\nEnter a number: ");       
    		   screen.flush();
    	   }
       }catch(InputMismatchException ime)
       {
    	   screen.println("Incorrect input.  Terminating.");
    	   screen.flush();
       }//end catch
       
       screen.println("Done.\n");       
       screen.flush();
    }
    
}
