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) {
5 Years
Discussion Span
Last Post by JeffGrigg
Featured Replies
  • 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 [url]http://www.java-forums.org/new-java/47262-creating-polynomial-using-linked-lists.html[/url] Read More


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.....

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.