Results 1 to 9 of 9
Like Tree1Likes
  • 1 Post By Norm

Thread: Creating polynomial using linked lists

  1. #1
    joe98 is offline Member
    Join Date
    Mar 2011
    Posts
    16
    Rep Power
    0

    Default Creating polynomial using linked lists

    public class Polynomial {
    /* Constructs a new polynomial of degree zero */
    public Polynomial() {
    }

    /* Returns an integer representing the coefficient
    * of the x^power term
    */
    int getCoefficients(int power) {
    }

    /* Sets the coefficient of the x^power term to coef. */
    void setCoefficients(int coef, int power) {
    }

    /* Returns the String representation of the polynomial.
    * For example, a polynomial can be represented as either
    * 3 * x^2 + 2 * x + 1 or
    * 3x^2 + 2x + 1
    * Any term whose coefficient is zero should not appear
    * in the string unless the polynomial has only a single
    * constant term of zero.
    */
    public String toString() {
    }

    /* Evaluates the polynomial for the value x and returns
    * the result p(x).
    */
    double evaluate(double x) {
    }

    /* Add to this polynomial the polynomial "other" and
    * return the resulting polynomial.
    */
    Polynomial add(Polynomial other) {
    }
    }
    Any idea

  2. #2
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,755
    Rep Power
    7

    Default

    Quote Originally Posted by joe98 View Post
    Any idea
    Yeah, I have an idea that I will go home and start my weekend. WOOHOO!

  3. #3
    joe98 is offline Member
    Join Date
    Mar 2011
    Posts
    16
    Rep Power
    0

    Default

    ok junky :P

  4. #4
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,755
    Rep Power
    7

    Default

    That was my subtle way to tell you to ask a better question.

  5. #5
    Hibernate's Avatar
    Hibernate is offline Senior Member
    Join Date
    Dec 2010
    Location
    Stockholm, Sweden
    Posts
    222
    Blog Entries
    9
    Rep Power
    4

    Default

    My idea:
    I think so should at least try to make one method, not just give us prototypes.
    Maybe should should start with the constructor, then evaluate, that seems fairly simple.

    Also drop the s from getCoefficients and setCoefficients, you do only set one coefficient per call.

    And if you want toString() to be real nice, substitute ↑ for ^, or better yet, use superscript (⁰⁴⁵⁶⁷⁸⁹).
    Ex animo! Hibernate
    Java, Arch Linux, C, GPL v3, Bash, Eclipse, Linux VT, GNOME 2 and many buttons on windows.

  6. #6
    Hibernate's Avatar
    Hibernate is offline Senior Member
    Join Date
    Dec 2010
    Location
    Stockholm, Sweden
    Posts
    222
    Blog Entries
    9
    Rep Power
    4

    Default

    When you have done that implement toString(), and add() by using getCoefficients() and setCoefficients(), and that leaves you with getCoefficients() and setCoefficients().

    Also, if all possible I would suggest not using linked lists, but two arrays (or look into hash tables/maps, that is even better and simpler), but I assume this is some kind of homework?
    Last edited by Hibernate; 08-05-2011 at 08:44 AM.
    Ex animo! Hibernate
    Java, Arch Linux, C, GPL v3, Bash, Eclipse, Linux VT, GNOME 2 and many buttons on windows.

  7. #7
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,548
    Rep Power
    23

    Default

    Cross posted at Polynomial java file - Java
    DarrylBurke likes this.

  8. #8
    JeffGrigg is offline Member
    Join Date
    Aug 2011
    Posts
    95
    Rep Power
    0

    Default

    Quote Originally Posted by Hibernate View Post
    And if you want toString() to be real nice, substitute ↑ for ^, or better yet, use superscript (⁰⁴⁵⁶⁷⁸⁹).
    Nifty! (I do keep forgetting that we're working with UNICODE here. ;-)

  9. #9
    Hibernate's Avatar
    Hibernate is offline Senior Member
    Join Date
    Dec 2010
    Location
    Stockholm, Sweden
    Posts
    222
    Blog Entries
    9
    Rep Power
    4

    Default

    It is okay to call it Unicode, but please don't hold down shift while pressing the six last keys.
    And you can [and should in some cases] use it in variable names [&c].
    Ex animo! Hibernate
    Java, Arch Linux, C, GPL v3, Bash, Eclipse, Linux VT, GNOME 2 and many buttons on windows.

Similar Threads

  1. singlie linked list polynomial addition
    By fusi0n556 in forum New To Java
    Replies: 0
    Last Post: 05-24-2011, 09:07 AM
  2. Creating a node for polynomial linked list
    By Java-Guy in forum New To Java
    Replies: 8
    Last Post: 03-17-2011, 08:27 PM
  3. Linked Lists
    By Dee in forum New To Java
    Replies: 18
    Last Post: 02-02-2011, 03:14 AM
  4. Linked Lists
    By vendetta in forum New To Java
    Replies: 6
    Last Post: 01-26-2010, 08:23 AM

Posting Permissions

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