class Polynomial { private double[] coefficient; public Polynomial (int degree) { coefficient = new double[degree+1]; } public int degree() { return coefficient.length-1; } public Polynomial multiply(Polynomial poly2) { Polynomial product; // Create the result polynomial product = new Polynomial(degree() + poly2.degree()); // For each term in the first polynomial for(int i = 0; i <= degree(); i++) { for(int j = 0; j <= poly2.degree(); j++) { product.coefficient[i+j] += coefficient[i]*poly2.coefficient[j]; } } } }