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) {
	}
}

Recommended Answers

All 4 Replies

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.

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

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.