我在尝试实现一个简单的面向对象程序时遇到了一些严重的问题。我有一个堆栈类定义如下...
import java.io.*;
public class stack
{
// instance variables - replace the example below with your own
private int maxStack;
private int emptyStack;
private int top;
private int[] stack;
public stack(int size)
{
maxStack = size;
emptyStack = -1;
top = emptyStack;
stack = new int[maxStack];
}
public int push(int y)
{
top++;
stack[top]= y;
return 0;
}
public int pull(int y){
int temp = top;
top--;
return stack[temp];
}
public boolean isEmpty(){
return top == emptyStack;
}
public void print(){
for(int i =top;i<0;i--){
System.out.println("Position "+top+" "+stack[top]);
}
}
}
I am trying to reference this class from another class that I am calling...
import java.io.*;
public class stackTest
{
public void stackStarter(){
System.out.println("Welcome to our Stack Simulator");
InputStreamReader ir = new InputStreamReader(System.in);
BufferedReader bf = new BufferedReader(ir);
System.out.print("Enter number of elements : ");
String str = bf.readLine();
int num = Integer.parseInt(str);
stack testStack = new stack(num);
int test =5;
testStack.push(test);
}
public static void main(String[] args){
stackStarter TEST = new stackStarter();
}
}
我不断收到错误...找不到符号 - 类 stackStarter。我尝试将 stackStarter 方法中的所有代码放在 main 中,但我无法从静态 main 方法访问 stack 类......有什么想法吗?