/** * Represents the polynomial abstraction. Holds the coefficient. Has two concrete * subclasses, ConstPoly and NonConstPoly, to form the composite pattern. * @author Dung X. Nguyen * @since 01/26/00 */ public abstract class APolynomial { /** * This APolynomial leading coefficient. */ protected double _coef; /** * Returns the leading coefficient of this APolynomial. */ public double getLeadCoef () { return _coef; } /** * Returns the degree (or order) of this APolynomial. */ public abstract int getDegree (); /** * Returns the lower ordered polynomial of this APolynomial, if any. * @exception throws NoSuchElementException if this APolynomial is a constant. */ public abstract APolynomial getLowerPoly (); /** * Computes and returns the sum of this APolynomial with the parameter p. * @param p an APolynomial to be added to this APolynomial. * @return an APolynomial representing the sum of this APolynomial and the parameter p. */ public abstract APolynomial add (APolynomial p); /** * Computes and returns the value of this APolynomial at a "point" x. * @param x the "point" at which this APolynomial is to be evaluated. * @return the value of this APolynomial evaluated at the parameter x. */ public abstract double eval (double x); /** * Called by an APolynomial that contains this APolynomial as its lower order polynomial. * Relegates to concrete subclass to compute the appropriate String for the lower * order polynomial if any. This is an example of we call a "helper" method for toString(). */ abstract String toString4LowerPoly (); }