@@ -0,0 +1,938 @@
+package newton;%0A%0A/** Represents a polynomial.%0A * @author Alan Ponte*/%0Apublic class Polynomial %7B%0A%09%0A%09/** Creates a new polynomial whose coefficients%0A%09 * are represented by the values in COEFFS.  E.G.%0A%09 * %5B1, 2, 2%5D -- %3E 1 + 2x + 2x%5E2%0A%09 */%0A%09public Polynomial(int%5B%5D coeffs) %7B%0A%09%09_coeffs = coeffs;%0A%09%09%0A%09%7D%0A%09%0A%09/** Returns the result of applying VAL to THIS polynomial.*/%0A%09public double valueAt(double val) %7B%0A%09%09/*If the polynomial is constant*/%0A%09%09if (_coeffs.length == 1) %7B%0A%09%09%09return _coeffs%5B0%5D;%0A%09%09%7D%0A%09%09double result = 0;%0A%09%09for (int i = 1; i %3C _coeffs.length; i += 1) %7B%0A%09%09%09result = result + ((Math.pow(val, i)) * (_coeffs%5Bi%5D));%0A%09%09%7D%0A%09%09return (double)result;%0A%09%09%0A%09%7D%0A%09%0A%09/** Returns THIS Polynomial's Coefficients.*/%0A%09public int%5B%5D getCoeffs() %7B%0A%09%09return _coeffs;%0A%09%09%0A%09%7D%0A%09%0A%09/** Sets THIS Polynomial's Coefficients to COEFFS.*/%0A%09public void setCoeffs(int%5B%5D coeffs) %7B%0A%09%09_coeffs = coeffs;%0A%09%7D%0A%09%0A%09/** THIS Polynomial's Coefficients.*/%0A%09private int%5B%5D _coeffs;%0A%0A%7D%0A

Create Polynomial.java