0
다른 사용자가 비슷한 질문을 던졌음에도 불구하고 내가 만든 두 클래스에 대한 기호 오류를 찾을 수없는 이유를 여전히 알 수없는 답변을 살펴 보았습니다. StacksAndQueuesProblems
디렉토리에서다른 파일에서 클래스를 찾을 수 없습니다.
FullStackException.java
fixedMultiStack.java
내가 javac threestacks/*.java
이 그러나 내가 얻을 다음을 실행하려고 다음 threestacks
디렉토리 안에이
StacksAndQueuesProblems/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);
}
}
'throw SomethingException ("some String"); 당신은 그것이 보이는 '새로운'것을 잊고 있습니다. –
인쇄상의 오류를 더 많이 남기기 위해 투표하는 중입니다. –
답장을 보내 주셔서 감사합니다. 그러나 그게 downvote의 장점이 있습니까? – fatalError