Results 1 to 5 of 5
  1. #1
    anthony303 is offline Member
    Join Date
    Nov 2015
    Posts
    2
    Rep Power
    0

    Default 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. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,422
    Blog Entries
    7
    Rep Power
    28

    Default 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
    Build a wall around Donald Trump; I'll pay for it.

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

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

    Quote Originally Posted by anthony303 View Post
    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.
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  4. #4
    anthony303 is offline Member
    Join Date
    Nov 2015
    Posts
    2
    Rep Power
    0

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

    Here is the Actual assignment. I'm working on project two.
    Help with ArrayList that works with two polynomials.-img_4999.jpg

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

    Default 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
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

Similar Threads

  1. Replies: 18
    Last Post: 03-26-2014, 11:43 PM
  2. String Polynomials
    By RawanS in forum New To Java
    Replies: 2
    Last Post: 04-16-2012, 09:21 AM
  3. orthogonal polynomials
    By yemsy in forum Threads and Synchronization
    Replies: 1
    Last Post: 02-17-2011, 11:40 AM
  4. gcd of two polynomials
    By mcherkao in forum Advanced Java
    Replies: 1
    Last Post: 09-25-2010, 12:51 AM
  5. Polynomials Arithmetic
    By thisisIT in forum New To Java
    Replies: 3
    Last Post: 03-09-2010, 02:27 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •