cannot find symbol error?

I keep getting an error in line 69 of code saying it cannot find the c

Page 1 of 1

2 Replies - 2719 Views - Last Post: 29 April 2009 - 03:11 PM Rate Topic: -----

#1 asoldier24  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 29-April 09

cannot find symbol error?

Post icon  Posted 29 April 2009 - 02:11 PM

I am pretty new to programming so this code may not be the most efficient or best way of doing this, but I cannot figure out what is wrong with my code. The error says cannot find symbol: constructor stack(). It occurs on the line Stack stack = new Stack();
I know it has something to do with passing in a constructor, but Ive tried several different things and cannot get it to work!

Thanks in advance for all your help!

package lab5;

/**
 *
 * @author 
 */
public class Main {

	/**
	 * @param args the command line arguments
	 */
	public static class Stack<E>
	{
		//initializing object and nodes
	private Object data;
	private Stack prev;
	private Stack next;
	private E[] elements;
	public int size;
	public int top;

		//constructor
	public Stack(Object d, Stack p, Stack n) {
		 data = d; prev = p; next = n; } // end of constructor
	public void setPrev(Stack where) { prev = where; } // end of setPrev method
	public void setNext(Stack where) { next = where; } // end of setNext method
	public Stack getPrev() { return prev; } // end of getPrev method
	public Stack getNext() { return next; } // end of getNext method
	public Object getData() { return data; } // end of getData method
	public void Stack(int s)
	{
		size = s > 0 ? s:100; //size of stack
		top = -1; // stack is initially empty
		elements = (E[]) new Object[size]; // creates array
	}
	public void push(E pushValue) // method for placing object on stack
	{
	   elements[top] = pushValue;// places new element on stack
	   top = top + 1;
	}
	public E pop() // Method for removing object from stack
	{
		top = top - 1;
		return elements[top];  // Returns element
	}

	public E peek() // Method for looking at last element, without removing it
	{
		return elements[top - 1]; // Shows element
	}

	public boolean empty() // Method to empty stack
	{
		return top == 0;
	}
	public E size()
	{
		return elements[size];
	}
	
} // end of Node class


	public static void main(String args[])
	{
		// TODO code application logic here
	   Stack stack = new Stack();
	   //Calls push function and places values in stack
	   stack.push(1);
	   stack.push(2);
	   stack.push(3);
	   stack.push(4);
	   stack.push(5);
	   System.out.println ("The size of stack is: " + stack.size());//Prints size of stack
	   System.out.println ("This is the stack: " + stack); // Prints stack
	   System.out.println ("Last element in: " + stack.pop()); // Calls pop function and prints last element
	   System.out.println ("Last element in: " + stack.pop());
	   System.out.println ("The size of stack is: " + stack.size());//Prints size of stack
	   System.out.println ("The stack is empty if 1, not empty if 0 : " + stack.empty()); // Tests of stack is empty
	   System.out.println ("Last element in: " + stack.pop());
	   System.out.println("Peek revealed: " + stack.peek());// Calls peek function and prints last element without removing it
	   System.out.println("Last element in: " + stack.pop());// Calls pop function and prints last element
	   System.out.println("Peek revealed: " + stack.peek());// Calls peek function and prints last element without removing it
	   System.out.println("Last element in: " + stack.pop());// Calls pop function and prints last element
	   System.out.println ("The stack is empty if 1, not empty if 0 : " + stack.empty()); // Tests of stack is empty
	}

}
 


Is This A Good Question/Topic? 0
  • +

Replies To: cannot find symbol error?

#2 Fuzzyness  Icon User is offline

  • Comp Sci Student
  • member icon

Reputation: 669
  • View blog
  • Posts: 2,438
  • Joined: 06-March 09

Re: cannot find symbol error?

Posted 29 April 2009 - 02:59 PM

public Stack(Object d, Stack p, Stack n)
That is your Constructor, and this is your Object instantiation:
Stack stack = new Stack();
You dont sent the neccesary parameters to the instantiation, so thats why it cant find the symbol.
Was This Post Helpful? 0
  • +
  • -

#3 asoldier24  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 29-April 09

Re: cannot find symbol error?

Posted 29 April 2009 - 03:11 PM

View PostFuzzyness, on 29 Apr, 2009 - 01:59 PM, said:

public Stack(Object d, Stack p, Stack n)
That is your Constructor, and this is your Object instantiation:
Stack stack = new Stack();
You dont sent the neccesary parameters to the instantiation, so thats why it cant find the symbol.



Ive tried passing the parameters, and I dont know if im just stupid, or what but that didnt work either. Do I have to create those parameters in the main class first? Then put them in?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1