how do you add elements to the top of a linked stack? i have most of code

this book i am reading through gives some code and code skeleton to explain how to use a linked stack. i have filled in all the code correctly...i think except for my push method which will add element to the top of a stack if its not full. it errors with the following:

cannot find symbol
symbol : constructor Node(java.lang.Object,Node)
location: class Node
Node newTop = new Node( val, top );
1 error
BUILD FAILED (total time: 0 seconds)

here is the node class required for the linkedstack class: (this came out of the book i am reading)

//************************************************************
// Node.java
// A general node for a singly linked list of objects.
//************************************************************
public class Node
{
private Node next;
private Object element;

//----------------
// Creates an empty node
//----------------
public Node()
{
next = null;
element = null;
}

//----------------
// Creates a node storing a specified element
//----------------
public Node(Object element)
{
next = null;
this.element = element;
}

//----------------
// Returns the node that follows this one
//----------------
public Node getNext()
{
return next;
}

//----------------
// Sets the node that follows this one
//----------------
public void setNext(Node node)
{
next = node;
}

//----------------
// Returns the element stored in this node
//----------------
public Object getElement()
{
return element;
}

//----------------
// Sets the element stored in this node
//----------------
public void setElement(Object element)
{
this.element = element;
}
}

ok, and here is my linkedstack class: problem is in the public void push(Object val) method:

// ****************************************************************
// LinkedStack.java
//
// An linked implementation of an Object stack class with operations push,
// pop, and isEmpty and isFull.
//
// ****************************************************************
public class LinkedStack implements StackADT
{
private Node top; // reference to top of stack

// ----------------
// Constructor -- initializes top
// ----------------
public LinkedStack()
{
top = null; // Creates an empty stack
}

// ----------------
// Adds element to top of stack if its not full, else
// does nothing.
// ----------------
public void push(Object val)
{
while (!isFull()) {
// Create a new node and make it point to the top of the stack
Node newTop = new Node( val, top );
// The top of the stack is in the new node
top = newTop;
}
}

// ----------------
// Removes and returns value at top of stack. If stack
// is empty returns null.
// ----------------
public Object pop()
{
if (isEmpty()) throw new RuntimeException("Stack underflow");
top = top.getNext();
return top.getElement();
}

// ----------------
// Returns true if stack is empty, false otherwise.
// ----------------
public boolean isEmpty()
{
return top == null;
}

// ----------------
// Returns true if stack is full, false otherwise.
// ----------------
public boolean isFull()
{
return false;
}
}
[4022 byte] By [dalearyous] at [2007-11-20 11:32:37]
# 1 Re: how do you add elements to the top of a linked stack? i have most of code
man still can't get this. shouldn't this work as well:

public void push(Object val)
{

if (isFull()) throw new RuntimeException("Stack is full");
// Create a new node and make it point to the top of the stack
top = new Node( val, top);

}

i get the exact same error
dalearyous at 2007-11-10 2:14:04 >
# 2 Re: how do you add elements to the top of a linked stack? i have most of code
You're calling the Node constructor and passing two arguments - but there is no Node constructor that takes two arguments - and that's exactly what the error message is saying.

At the source of every error which is blamed on the computer, you will find at least two human errors, one of which is the error of blaming it on the computer...
T. Gilb.
dlorde at 2007-11-10 2:15:05 >
# 3 Re: how do you add elements to the top of a linked stack? i have most of code
i ruled out problem being with node class because it came from book. this is what i modified and it compiles. will this run correctly though?

//************************************************************
// Node.java
// A general node for a singly linked list of objects.
//************************************************************
public class Node
{
private Node next;
private Object element;

//----------------
// Creates an empty node
//----------------
public Node(Object theElement, Node n)
{
next = n;
element = theElement;
}

//----------------
// Creates a node storing a specified element
//----------------
public Node(Object element)
{
next = null;
this.element = element;
}

//----------------
// Returns the node that follows this one
//----------------
public Node getNext()
{
return next;
}

//----------------
// Sets the node that follows this one
//----------------
public void setNext(Node node)
{
next = node;
}

//----------------
// Returns the element stored in this node
//----------------
public Object getElement()
{
return element;
}

//----------------
// Sets the element stored in this node
//----------------
public void setElement(Object element)
{
this.element = element;
}
}

no this for some reason doesn't work:

public class StackTest
{
public static void main(String[] args)
{
StackADT stack = new LinkedStack();

//push some stuff on the stack
for (int i=0; i<10; i++)
stack.push(i*2);

//pop and print
//should print 18 16 14 12 10 8 6 4 2 0
while (!stack.isEmpty())
System.out.print(stack.pop() + " ");
System.out.println();

//push a few more things
for (int i=1; i<=6; i++)
stack.push(i);

//should print 5 4 3 2 1
while (!stack.isEmpty())
System.out.print(stack.pop() + " ");
System.out.println();

}
}
dalearyous at 2007-11-10 2:16:04 >
# 4 Re: how do you add elements to the top of a linked stack? i have most of code
i ruled out problem being with node class because it came from book.Anyone can write a book on Java without being a Java expert, and can even be very successful at it (e.g. Herb Schildt), and code often gets mangled between author and printer. In my experience code in books is generally unreliable and should only be used as a guideline.

If you do copy code from a book, you should make sure you understand exactly what it does.
this is what i modified and it compiles. will this run correctly though?
...
no this for some reason doesn't work:So now you have to debug it. Debugging is the secret core of Java programming.

I suggest you step through the code by hand, writing down the values of the variables as they change. Pay particular attention to the 'pop()' method - you should see the problem very quickly.

Good programmers know what's beautiful and bad ones don't...
D. Gelernter
dlorde at 2007-11-10 2:17:11 >