what am i doing wrong here?

I'm using an arraylist to multiply polynomials, but it doesn't work correctly:

Code:

` public void times (Poly b) {`

for ( int p_a = 0 ; p_a < polynomial.size() ; p_a++ ) {

Term temp = polynomial.get(p_a);

for ( int p_b = 0 ; p_b < b.polynomial.size() ; p_b++ ) {

polynomial.set(p_a,temp.times(b.polynomial.get(p_b)));

}

}

}

Code:

` public Term times (Term term) {`

Term temp = new Term(coefficient *= term.coefficient, exponent += term.exponent);

return temp;

}

ex. (x^2+3x-1)*(7-x^2+2x^3)

The correct answer would be 2x^5+5x^4-5x^3+8x^2+21x-7,

but in stead it gives me -14x^7-42x^6+14x^5

I believe this is because it updates polynomial(p_a) after each loop and uses that new value in the next loop. Which is odd, because I put in a temp Term for exactly that reason.