package polyVisitor; import arrayPoly.*; /** * Evaluates the host polynomial at a double input. Returns a Double.
 * Copyright 2000, by Dung X. Nguyen, All rights reserved.
 
* @author Dung X. Nguyen * @since 02/16/2000 */ public class EvalAlgo implements IVisitor { public final static EvalAlgo Singleton = new EvalAlgo (); private EvalAlgo() { } /** * @param poly * @param input an Double * @return the constant Double value of poly. */ public Object forConst (APolynomial poly, Object input) { return new Double (poly.getLeadCoef()); } /** * @param poly * @param input an Integer * @return the Integer value of poly evaluated at input. */ public Object forNonConst (APolynomial poly, Object input) { double x = ((Double)input).intValue (); double leadVal = poly.getLeadCoef () * Math.pow (x, poly.getDegree ()); double lowerVal = ((Double)poly.getLowerPoly().execute(this, input)).doubleValue (); return new Double (leadVal + lowerVal); } }