Results 1 to 5 of 5
 02272016, 04:15 AM #1Member
 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
 02272016, 07:47 AM #2
 Join Date
 Sep 2008
 Location
 Voorschoten, the Netherlands
 Posts
 14,422
 Blog Entries
 7
 Rep Power
 29
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,
JosBuild a wall around Donald Trump; I'll pay for it.
 02272016, 04:12 PM #3Senior Member
 Join Date
 Jan 2013
 Location
 Northern Virginia, United States
 Posts
 6,226
 Rep Power
 14
Re: Help with ArrayList that works with two polynomials.
Last edited by jim829; 02272016 at 06:14 PM.
The Java^{TM} Tutorials  SSCCE  Java Naming Conventions
Poor planning on your part does not constitute an emergency on my part
 02282016, 12:32 AM #4Member
 Join Date
 Nov 2015
 Posts
 2
 Rep Power
 0
 02282016, 01:31 AM #5Senior Member
 Join Date
 Jan 2013
 Location
 Northern Virginia, United States
 Posts
 6,226
 Rep Power
 14
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,
JimThe Java^{TM} Tutorials  SSCCE  Java Naming Conventions
Poor planning on your part does not constitute an emergency on my part
Similar Threads

Works in Netbeans, works in Eclipse, doesn't work after being compiled by either
By ZhiMing in forum New To JavaReplies: 18Last Post: 03262014, 10:43 PM 
String Polynomials
By RawanS in forum New To JavaReplies: 2Last Post: 04162012, 08:21 AM 
orthogonal polynomials
By yemsy in forum Threads and SynchronizationReplies: 1Last Post: 02172011, 10:40 AM 
gcd of two polynomials
By mcherkao in forum Advanced JavaReplies: 1Last Post: 09242010, 11:51 PM 
Polynomials Arithmetic
By thisisIT in forum New To JavaReplies: 3Last Post: 03092010, 01:27 PM
Bookmarks