我遇到了一些严重的问题,试图实现一个简单的面向对象的程序。我有一个堆栈类定义如下...类混乱,编写堆栈模拟器
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方法中的所有代码,但我不能从静态主要方法访问堆类...任何想法?
“拉”?!谁拉了一堆? –