package funpoly; import funpoly.visitor.IVisitor; /** * Represents the constant polynomial type. * @author Dung X. Nguyen */ class ConstPoly extends APolynomial { /** * @param coef the coefficient. */ ConstPoly(int coef) { _coef = coef; } public int getDegree() { return (0); } /** * Throws NoSuchElementException. */ public APolynomial getLowerPoly() { throw new java.util.NoSuchElementException ("Constant polynomial has no lower order term!"); } public String toString () { return Integer.toString(_coef); } String toStringHelp () { return (0 == _coef)? "": " + " + Integer.toString(_coef); } /** * Calls algo.forConst to carry out the task. */ public Object execute(IVisitor algo, Object input) { return algo.forConst(this, input); } }