我遇到了一些嚴重的問題,試圖實現一個簡單的面向對象的程序。我有一個堆棧類定義如下...類混亂,編寫堆棧模擬器
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方法中的所有代碼,但我不能從靜態主要方法訪問堆類...任何想法?
「拉」?!誰拉了一堆? –