Results 1 to 9 of 9
- 08-05-2011, 07:52 AM #1
Member
- Join Date
- Mar 2011
- Posts
- 16
- Rep Power
- 0
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 #2
- 08-05-2011, 08:10 AM #3
Member
- Join Date
- Mar 2011
- Posts
- 16
- Rep Power
- 0
ok junky :P
- 08-05-2011, 08:13 AM #4
That was my subtle way to tell you to ask a better question.
- 08-05-2011, 08:39 AM #5
- Join Date
- Dec 2010
- Location
- Stockholm, Sweden
- Posts
- 222
- Blog Entries
- 9
- Rep Power
- 3
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.
- 08-05-2011, 08:41 AM #6
- Join Date
- Dec 2010
- Location
- Stockholm, Sweden
- Posts
- 222
- Blog Entries
- 9
- Rep Power
- 3
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.
- 08-05-2011, 02:17 PM #7
Cross posted at Polynomial java file - Java
- 08-05-2011, 03:03 PM #8
Member
- Join Date
- Aug 2011
- Posts
- 95
- Rep Power
- 0
- 08-06-2011, 05:29 AM #9
- Join Date
- Dec 2010
- Location
- Stockholm, Sweden
- Posts
- 222
- Blog Entries
- 9
- Rep Power
- 3
Similar Threads
-
singlie linked list polynomial addition
By fusi0n556 in forum New To JavaReplies: 0Last Post: 05-24-2011, 09:07 AM -
Creating a node for polynomial linked list
By Java-Guy in forum New To JavaReplies: 8Last Post: 03-17-2011, 08:27 PM -
Linked Lists
By Dee in forum New To JavaReplies: 18Last Post: 02-02-2011, 03:14 AM -
Linked Lists
By vendetta in forum New To JavaReplies: 6Last Post: 01-26-2010, 08:23 AM


1Likes
LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks