// PolynomialDemo.java // Developed in class on 29-July-2008 // NOT YET COMPLETED (not even up to "in-class standards") import java.util.*; public class PolynomialDemo { public static Scanner scanner = new Scanner(System.in); public static void testPolynomial() { System.out.println("Testing Polynomial class..."); Polynomial p = new Polynomial(3, 2, -4); System.out.println(p + "(2) = " + p.eval(2)); assert(p.eval(2) == 12); System.out.println("PASSED ALL TESTS!"); } public static void main(String[] args) { testPolynomial(); } } class Polynomial { // instance variables // coeffs[0] is the 1's coeff, so coeffs[k] is the n^k coeff private int[] coeffs; // constructor public Polynomial(int a, int b, int c) { this.coeffs = new int[3]; coeffs[0] = c; coeffs[1] = b; coeffs[2] = a; } // using "pow" for "eval" is slower but perhaps clearer private int pow(int x, int k) { assert(k >= 0); int result = 1; while (k-- > 0) result *= x; return result; } // eval public int eval(int x) { int result = 0; for (int k=0; k