我已经查看了其他用户提出类似问题的答案,但仍然无法弄清楚为什么我无法找到两个类别的符号错误我已经创建
我的目录看起来像这样
StacksAndQueuesProblems/threestacks
在threestacks
目录中,我有以下.java
个文件:
FullStackException.java
fixedMultiStack.java
我试图执行的StacksAndQueuesProblems
目录javac threestacks/*.java
但是我收到以下错误:
threestacks/fixedMultiStack.java:20: error: cannot find symbol
throw FullStackException("ERR: That stack is full!");
^
FullStackException.java
package threestacks;
public class FullStackException extends Exception {
public FullStackException(String message) {
super(message);
}
}
fixedMultiStack.java
package threestacks;
class fixedMultiStack {
private int numberOfStacks = 3;
private int stackCapacity;
private int[] values;
private int[] sizes;
public fixedMultiStack(int stackCapacity) {
this.stackCapacity = stackCapacity;
values = new int[stackCapacity * numberOfStacks]; // Holds all 3 stacks
sizes = new int[numberOfStacks+1]; // Holds the number of items in each stack
}
/* push value onto stack */
public void push(int stackNum, int value) throws FullStackException {
/* check if we have space on the stack for the element */
if (isFull(stackNum)) {
throw FullStackException("ERR: That stack is full!");
}
/* increment stack pointer and then insert the value */
sizes[stackNum]++; // Increment the number of items for that stack
values[indexOfTop(stackNum)] = value; // Insert the value into the array
}
/* Pop item from the stack */
public void pop(int stackNum) {
if (isEmpty(stackNum)) {
throw new EmptyStackException();
}
/* Retreive the value and decrement the stack pointer */
int topIndex = indexOfTop(stackNum);
int value = values[topIndex]; //Get top
values[topIndex] = 0; // Clear
sizes[stackNum]--; // Decrement the size of the stack
}
/* Return top element */
public int peek(int stackNum) {
if (isEmpty(stackNum)) {
throw new EmptyStackException();
}
int topIndex = indexOfTop(stackNum);
int value = values[topIndex];
return value;
}
/* Return if stack is empty */
public boolean isEmpty(int stackNum) {
return sizes[stackNum] == 0;
}
/* Return if stack is full */
public boolean isFull(int stackNum) {
return sizes[stackNum] == stackCapacity;
}
/* Returns index of top of stack */
public int indexOfTop(int stackNum) {
return ((stackNum -1) * stackCapacity + sizes[stackNum] - 1);
}
}
答案 0 :(得分:0)
fixedMultiStack.java文件中存在编译错误。它应该是
throw new FullStackException("ERR: That stack is full!");