package lectureDemo; import javax.swing.JOptionPane; /* * Created on Dec 11, 2007 * */ /** * @author hornick * */ public class ExceptionsDemoApp { /** * standard main() method */ public static void main(String[] args) { double value = getValueFromUser(); double root = computeSquareRoot(value); String output = String.format("Square root of %f is %f", value, root); JOptionPane.showMessageDialog(null, output); } /** * This method asks the user for input */ public static double getValueFromUser() { String strInput = JOptionPane.showInputDialog(null, "Enter a positive number less that 1000:"); // just try to parse whatever was entered double num = Double.parseDouble(strInput); return num; } /** * This method computes the square root of a value */ public static double computeSquareRoot(double value) { double root = Math.sqrt(value); return root; } }