# Thread: Help with ArrayList that works with two polynomials.

1. Member
Join Date
Nov 2015
Posts
2
Rep Power
0

## Help with ArrayList that works with two polynomials.

I'm working on a program for class that should take in coefficients and exponents from the user and should display them in polynomial form, their sum, and their product. I am really stuck with this program and am looking for guidance as to how to accomplish this. For this program I am really only allowed to use the ArrayList class and that's basically it. I can't use collections and other stuff like that since I have not learned it in class. I really just need guidance for an approach to accomplish this program. Any feedback, sample code, etc is GREATLY appreciated.
I know some of this code is sloppy and may not be needed. Keep in mind I am pretty new to java.
I've also been able to sort the exponents greatest to least and can obtain the coefficients and exponents of a given polynomial.

Some sample output would be:

Enter the first polynomial. Enter 0 0 to quit. 3 2 2 1 6 2 8 0 0 0 Enter second Polynomial. Enter 0 0 to quit. 7 1 5 0 0 0 Here are the two polynomials. 9x2 + 2x1 + 8 7x1 + 5
Here is their sum. 9x2 + 9x1 + 13
Here is their product. 63x3 + 59x2 + 66x + 40

https://gist.github.com/anonymous/d713981c899dc2cca26c

2. ## Re: Help with ArrayList that works with two polynomials.

If you can add two entire polynomials, you can multiply two entire polynomials; all you need is a small method that multiplies an entire polynomial and a single term.
e.g. (3+2x)*(4+x) == 3*4+3*x + 2x*4+2x*x == 12+3*x+8*x+2*x^2 etc.

kind regards,

Jos

3. Senior Member
Join Date
Jan 2013
Location
Northern Virginia, United States
Posts
6,226
Rep Power
13

## Re: Help with ArrayList that works with two polynomials.

Originally Posted by anthony303
Enter the first polynomial. Enter 0 0 to quit. 3 2 2 1 6 2 8 0 0 0 Enter second Polynomial. Enter 0 0 to quit. 7 1 5 0 0 0 Here are the two polynomials. 9x2 + 2x1 + 8 7x1 + 5
Is there a mistake here? How does 3 2 2 1 6 2 8 0 0 0 equate to 9x2 + 2x1 + 8? Shouldn't it be 9 2 2 1 8 0 0 0?
Just checking to ensure I understand the notation.

Regards,
Jim
Last edited by jim829; 02-27-2016 at 07:14 PM.

4. Member
Join Date
Nov 2015
Posts
2
Rep Power
0

## Re: Help with ArrayList that works with two polynomials.

Here is the Actual assignment. I'm working on project two.

5. Senior Member
Join Date
Jan 2013
Location
Northern Virginia, United States
Posts
6,226
Rep Power
13

## Re: Help with ArrayList that works with two polynomials.

I realize what is going on now. The 3 2 and 6 2 are combined to form 9 2. So the actual literal polynomial entered, in order, was
3x^2 + 2x^1 + 6x^2 + 8x^0

Regards,
Jim