We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,285 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Polynomial java file

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) {
	}
}
4
Contributors
4
Replies
3 Days
Discussion Span
1 Year Ago
Last Updated
5
Views
hamiltino
Newbie Poster
3 posts since Aug 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

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

NormR1
Posting Sage
Team Colleague
7,742 posts since Jun 2010
Reputation Points: 1,158
Solved Threads: 793
Skill Endorsements: 16

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.

JeffGrigg
Posting Whiz in Training
220 posts since Aug 2011
Reputation Points: 192
Solved Threads: 28
Skill Endorsements: 0

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

javaGenius
Newbie Poster
1 post since Aug 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 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.

JeffGrigg
Posting Whiz in Training
220 posts since Aug 2011
Reputation Points: 192
Solved Threads: 28
Skill Endorsements: 0

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.0679 seconds using 2.67MB