/** * @(#)NewtonRaphsonTester.java * * NewtonRaphsonTester application * * @author Michael McClelland, Leo Gorokhovsky * @version 1.00 2007/5/16 */ import javax.swing.JOptionPane; public class NewtonRaphsonTester { public static void main(String[] args) { System.out.println("This program will solve for zeros of equations of the from of: f(x)= X^n-a");//prompt display menu();//initiate menu to display } public static void test() { int n=0;//init n to 0 double precision=0.00001,a=0;//precision set to 0 and a init. String userAnswer; try{ System.out.println("Please Enter values for the equation with respect to:\nf(x) = x^n - a"); //prompt display precision = Math.abs(Double.parseDouble(JOptionPane.showInputDialog("Value for precision? - Enter a decimal value")));//JOptionPane Dialogue n = Integer.parseInt(JOptionPane.showInputDialog("Value for n? - Enter an Integer greater than 0 - input will be treated as signless")); System.out.println("Value for a? - Enter an Integer greater than 0 - input will be treated as signless"); a = Integer.parseInt(JOptionPane.showInputDialog("Value for a? - Enter an Integer greater than 0 - input will be treated as signless")); System.out.println("Summery:\nprecision=" + precision + "\nn=" + n + "\na=" + a); userAnswer = JOptionPane.showInputDialog("Is this correct?\nEnter yes or y - all other inputs will restart the test"); if ((userAnswer.equalsIgnoreCase("yes")) || (userAnswer.equalsIgnoreCase("y"))) System.out.println("Starting approximation"); else { System.out.println("Summery not approved or bad input - restarting"); test(); } } catch (NumberFormatException e) { System.out.println("Bad input - restarting"); test(); } NRaphson g = new NRaphson(n,a,precision); do { g.nextApproximation(); System.out.println(g.getApprox()); } while (g.closeEnough()); } public static void autoTest() { int qq=0,correct=0,a=0,n=0; double u,nth,oracle,precision=0.00001; try{ precision = Math.abs(Double.parseDouble(JOptionPane.showInputDialog("Value for precision? - Enter a decimal value"))); int tests; tests = Math.abs(Integer.parseInt(JOptionPane.showInputDialog("Perform how many tests??"))); while (qq