/**
 *                  Square root program to read in a double
 *                   and print out the square root to 4 sig figs
 *                   with test to trap negative numbers
 *
 */

import uk.ac.ed.ph.sciprog.*;

public class SquareRoot {
    public static void main(String args[]) {
	
	//                Make up the display panel to ask for one double

	Display panel = new Display("Square Rooter");
	Input valueInput = new Input("Value", 0.0);
	panel.addInput(valueInput);


	//                  Start of loop reading from Dsiplay
	while(true){

	    panel.waitForButtonPress();

	    double value = valueInput.getDouble();  // Read value

	    if (value < 0 ) {                   // Trap negative

		panel.println("Negative number given");
	    }
	    else {                             // Print out sqrt to 4 sig figs
		panel.printf("Square root of %.7g is : %.7g\n", 
			     value,Math.sqrt(value));
	    }
	}
    }
}
