/*              Simple example to demonstrate the use of
 *              the static method 
 *
 *        double quadratic(double,double,double,double);
 */

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

public class QuadCalc {

    //     Declare a static method to fcalcualte a quadratic

     static double quadratic(double a, double b, double c, double x) {
        double value = a*x*x + b*x + c;
        return value;                          // Return the value
       }

    //              main program
              
     public static void main(String args[]) {
	  //            Setup Display to ask for three inputs
	  //            in vetor form

	  Display panel = new Display("Quadratic Calculator");
	  double defaults[] = {1.0,1.0,1.0};
	  Input coefInput = new Input("Coefficients",defaults);
	  panel.addInput(coefInput);

	  //             Input to get the x value

	  Input xInput = new Input("X value",1.0);
	  panel.addInput(xInput);

	  while(true) {
	      panel.waitForButtonPress();

	      //              Read the three coefficeints + x value
	      double a = coefInput.getDouble(0);
	      double b = coefInput.getDouble(1);
	      double c = coefInput.getDouble(2);
	      double x = xInput.getDouble();

	      //        Call static method to calcualte the quadratic

	      double calculatedValue = quadratic(a,b,c, x);

	      //          print out the result

	      panel.printf("Value of quadratic is %.6g\n",calculatedValue);
	  }

      }
}
