1,105,534 Community Members

Polynomial java file

Member Avatar
hamiltino
Newbie Poster
3 posts since Aug 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Can someone help me and complete this simple polynomial program(can be demonstrated 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) {
	}
}
Member Avatar
NormR1
Posting Sage
7,723 posts since Jun 2010
Reputation Points: 563 [?]
Q&As Helped to Solve: 793 [?]
Skill Endorsements: 16 [?]
Team Colleague
 
1
 

Do you have a question about your code?
Please explain what you have tried and what problems you are having.

See the answers on your other post at http://www.java-forums.org/new-java/47262-creating-polynomial-using-linked-lists.html

Member Avatar
JeffGrigg
Posting Whiz in Training
251 posts since Aug 2011
Reputation Points: 153 [?]
Q&As Helped to Solve: 31 [?]
Skill Endorsements: 0 [?]
 
0
 

This is homework. You should write the code. You'll learn better that way.

A hint to help you get started: Consider the relationship between int power and the LinkedList index. Doing this might inspire a really good idea.

Member Avatar
javaGenius
Newbie Poster
1 post since Aug 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Why do not u use array? thaz much easier.....

Member Avatar
JeffGrigg
Posting Whiz in Training
251 posts since Aug 2011
Reputation Points: 153 [?]
Q&As Helped to Solve: 31 [?]
Skill Endorsements: 0 [?]
 
0
 

Why do not u use array? thaz much easier.....

Because you don't know in advance how many entries will be needed. The implementations of 'java.lang.List' let you add entries at runtime very easily. Personally, I would favor ArrayList for this assignment. But linked lists were mentioned, so maybe the instructor expects LinkedList.

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article