Errors in Polynomial Class
<p>I'm having some problems with some methods that I created for a polynomial class. For the <code>CheckZero</code>, we're supposed to check if there are any leading zeros in the coefficients of the polynomial. If there are, it should re-size the coefficient array but shouldn't return anything. I can't get it to run properly. For the Differentiate method I constantly get a <code>ArrayIndexOutOfBounds</code> Error.</p>

<pre><code>import java.util.ArrayList;
public class Poly {

    private float[] coefficients;
    public static void main (String[] args){
        float[] fa = {3, 2, 4};
        Poly test = new Poly(fa);

    }

    public Poly() {
        coefficients = new float[1];
        coefficients[0] = 0;
    }

    public Poly(int degree) {
        coefficients = new float[degree+1];
        for (int i = 0; i &lt;= degree; i++)
            coefficients[i] = 0;
    }


    public Poly(float[] a) {
        coefficients = new float[a.length];
        for (int i = 0; i &lt; a.length; i++)
            coefficients[i] = a[i];
    }

    public int getDegree() {
        return coefficients.length-1;
    }

    public float getCoefficient(int i) {
        return coefficients[i];
    }

    public void setCoefficient(int i, float value) {
        coefficients[i] = value;
    }

    public Poly add(Poly p) {
        int n = getDegree();
        int m = p.getDegree();
        Poly result = new Poly(Poly.max(n, m));
        int i;

            for (i = 0; i &lt;= Poly.min(n, m); i++) 
                result.setCoefficient(i, coefficients[i] + p.getCoefficient(i));
            if (i &lt;= n) {
                //we have to copy the remaining coefficients from this object
                for ( ; i &lt;= n; i++) 
                    result.setCoefficient(i, coefficients[i]);
            } else {
                // we have to copy the remaining coefficients from p
                for ( ; i &lt;= m; i++) 
                    result.setCoefficient(i, p.getCoefficient(i));
            }
        return result;
    }

    public void displayPoly () {
        for (int i=0; i &lt; coefficients.length; i++)
            System.out.print(" "+coefficients[i]);
        System.out.println();
    }

    private static int max (int n, int m) {
        if (n &gt; m)
            return n;
        return m;
    }

    private static int min (int n, int m) {
        if (n &gt; m)
            return m;
        return n;
    }

    public Poly multiplyCon (double c){
        int n = getDegree();
        Poly results = new Poly(n);
        for (int i =0; i &lt;= n; i++){ // can work when multiplying only 1 coefficient
            results.setCoefficient(i, (float)(coefficients[i] * c)); // errors ArrayIndexOutOfBounds for setCoefficient
           }

        return results;
       }

    public Poly multiplyPoly (Poly p){
        int n = getDegree();
        int m = p.getDegree();
        Poly result = null;
        for (int i = 0; i &lt;= n; i++){
            Poly tmpResult = p.multiByConstantWithDegree(coefficients[i], i); //Calls new method
            if (result == null){
                result = tmpResult;
            } else {
                result = result.add(tmpResult);
            }
        }
        return result;
    }
    public void checkZero(){
        int newDegree = getDegree();
        int length = coefficients.length;
        float testArray[] = coefficients;
        for (int i = coefficients.length-1; i&gt;0; i--){
            if (coefficients[i] != 0){
                testArray[i] = coefficients[i];

            } 
            }
        for (int j = 0; j &lt; testArray.length; j++){
            coefficients[j] = testArray[j];
        }
    }    

    public Poly differentiate(){
        int n = getDegree();
        int newPolyDegree = n - 1;
        Poly newResult = new Poly();
        if (n == 0){
            newResult.setCoefficient(0, 0);
        }
        for (int i =0; i&lt;= n; i++){
            newResult.setCoefficient(i, coefficients[i+1] * (i+1));
        }
        return newResult;
    }


    public Poly multiByConstantWithDegree(double c, int degree){ //used specifically for multiply poly
        int oldPolyDegree = this.getDegree();
        int newPolyDegree = oldPolyDegree + degree;
        Poly newResult = new Poly(newPolyDegree);
        //set all coeff to zero
        for (int i = 0; i&lt;= newPolyDegree; i++){
            newResult.coefficients[i] = 0;
        }
        //shift by n degree
        for (int j = 0; j &lt;= oldPolyDegree; j++){
            newResult.coefficients[j+degree] = coefficients[j] * (float)c;
        }

        return newResult;
    }
}
</code></pre>

<p>Edit: whoops. Copied the wrong version. Fixed</p>
