I am working on an assignment and I need a bit of help. I am using a double linked list to find roots of polynomials, the list has a trailer node only. I can't seem to get it to create a list. I figure I am just missing something small or not understanding a small part.

public class Polynomial
{

	private Node top;

	public Polynomial()
	{
		Node trailer = new Node("","",null, null);
		top.setNext(trailer);

	}
}
class Node{

	private double coef;
	private int degree;
	private Node next;
	private Node prev;

	public Node(double coef, int degree, Node newNext, Node newPrev)
	{
		this.coef = coef;
		this.degree = degree;
		next = newNext;
		prev = newPrev;

	}
	public void setNext(Node newNext)
	{
		next = newNext;
	}
}//there is more code in the node class, but is not being used yet

//this is the main method that creates the polynomial class(which is the linked list)
public static void main(String[] args)
{
	Polynomial poly= new Polynomial();

	poly.set(2.0, 3);

}

the problem seem to happen when I try to create the new Polynomial, " Polynomial poly= new Polynomial();". I get the error

Polynomial.java:8: cannot find symbol
symbol : constructor Node(java.lang.String,java.lang.String,<nulltype>,<nulltype>)
location: class Node
Node trailer = new Node("","",null, null);

I know I'm passing 2 strings, I'm not sure how to make this Node empty, since it stores a double and an int.

I am working on an assignment and I need a bit of help. I am using a double linked list to find roots of polynomials, the list has a trailer node only. I can't seem to get it to create a list. I figure I am just missing something small or not understanding a small part.

public class Polynomial
{

	private Node top;

	public Polynomial()
	{
		Node trailer = new Node("","",null, null);
		top.setNext(trailer);

	}
}
class Node{

	private double coef;
	private int degree;
	private Node next;
	private Node prev;

	public Node(double coef, int degree, Node newNext, Node newPrev)
	{
		this.coef = coef;
		this.degree = degree;
		next = newNext;
		prev = newPrev;

	}
	public void setNext(Node newNext)
	{
		next = newNext;
	}
}//there is more code in the node class, but is not being used yet

//this is the main method that creates the polynomial class(which is the linked list)
public static void main(String[] args)
{
	Polynomial poly= new Polynomial();

	poly.set(2.0, 3);

}

the problem seem to happen when I try to create the new Polynomial, " Polynomial poly= new Polynomial();". I get the error

Polynomial.java:8: cannot find symbol
symbol : constructor Node(java.lang.String,java.lang.String,<nulltype>,<nulltype>)
location: class Node
Node trailer = new Node("","",null, null);

I know I'm passing 2 strings, I'm not sure how to make this Node empty, since it stores a double and an int.

The signature of your node is still expecting 4 arguments whether or not you've specified them as null or not (what do they do exactly? Do you even need them?) So you are calling a constructor that is not defined in your class. Java supports overloading. Create a constructor that only accepts 2 arguments or just get rid of the nulls. If you need to use them later, add them later when you're ready to implement what they should do.

Go step by step
Create from scratch class Polynomial
implement set( , get( , String toString() methods
and show

When the polynomial is created, a trailer node is created that, at the moment it's created, points to null both forwards and backwards. The node will store an double that is the coefficient and an int that is the degree(x^(int)). the trailer node is supposed to be empty. that is where "Node trailer = new Node("","",null, null);" tries to create the empty node that point to null twice.

Yes, and they answered your question already. The reason it isn't working is because

Node trailer = new Node("","",null, null);

is invalid because "" and "" are Strings. You did not write a constructor method that takes two Strings followed by two Nodes. Your constructor takes a double, an int, then two Nodes.

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.