package funpoly; import funpoly.visitor.IVisitor; /** * Represents the non-constant polynomial type. Holds a postive degree (or order) * and a polynomial of lower order. * @author Dung X. Nguyen */ class NonConstPoly extends APolynomial { /** * Data Invariant: 0 < _degree. */ private int _degree; /** * Data Invariant: _lowerPoly._degree < _degree. * @SBGen Variable (,lower order polynomial,,64) */ private APolynomial _lowerPoly; /** * @param coef the coefficient * @param degree the degree, > 0. * @param lowPoly the lower ordered polynomial. */ NonConstPoly(int coef, int degree, APolynomial lowPoly) { _coef = coef; _degree = degree; _lowerPoly = lowPoly; } public int getDegree() { return _degree; } public APolynomial getLowerPoly() { return _lowerPoly; } public String toString () { return Integer.toString(_coef) + "x^" + Integer.toString(_degree) +_lowerPoly.toStringHelp(); } String toStringHelp () { return " + " + toString (); } /** * Calls algo.forNonConst (...). */ public Object execute(IVisitor algo, Object input) { return algo.forNonConst (this, input); } }