# Creating polynomial using linked lists

Printable View

• 08-05-2011, 07:52 AM
joe98
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
• 08-05-2011, 07:57 AM
Junky
Quote:

Originally Posted by joe98
Any idea

Yeah, I have an idea that I will go home and start my weekend. WOOHOO!
• 08-05-2011, 08:10 AM
joe98
ok junky :P
• 08-05-2011, 08:13 AM
Junky
That was my subtle way to tell you to ask a better question.
• 08-05-2011, 08:39 AM
Hibernate
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 (⁰¹²³⁴⁵⁶⁷⁸⁹).
• 08-05-2011, 08:41 AM
Hibernate
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?
• 08-05-2011, 02:17 PM
Norm
Cross posted at Polynomial java file - Java
• 08-05-2011, 03:03 PM
JeffGrigg
Quote:

Originally Posted by Hibernate
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. ;-)
• 08-06-2011, 05:29 AM
Hibernate
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].