// A class that represents quadratic functions, i.e., functions of // the form // f(x) = ax^2 + bx + c // History // // January 2007 -- Created by Doug Baldwin as part of a prototype // solution to a CSci 240 exercise. class Quadratic implements Function { // Internally, quadratic functions store their a, b, and c coefficients: private double a; private double b; private double c; // The constructor. This simply initializes the function's coefficients // from values provided by the client. public Quadratic( double a, double b, double c ) { this.a = a; this.b = b; this.c = c; } // Evaluate a quadratic function. The parameter to this method is the // x value at which to evaluate the function, and the return value is // the function's value at that x. public double value( double x ) { return a * x * x + b * x + c; } // Generate a string representation of a quadratic function. public String toString() { return a + " x^2 + " + b + " x + " + c; } }