I've looked at answers other users have asked for similar question and still can't figure out why I'm getting can't find symbol errors for two classes I've created.
My dir looks like this
StacksAndQueuesProblems/threestacks
inside the threestacks
directory, I have the following .java
files:
FullStackException.java
fixedMultiStack.java
From the StacksAndQueuesProblems
directory I tried to execute javac threestacks/*.java
however I get the following error:
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);
}
}