2017-02-01 10 views
0

Я просмотрел ответы, которые другие пользователи задали по аналогичному вопросу и до сих пор не могут понять, почему я получаю не могу найти ошибки символов для двух классов, которые я создал.Не можете найти класс в другом файле

Мой реж выглядит так

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

Не должно быть 'throw new SomethingException (" some String ");'? Вы забываете «новое», похоже. –

+0

Голосование, чтобы закрыть больше типографской ошибки. –

+0

Спасибо за ваш ответ, но это заслуживает понижения? – fatalError

ответ

0

Существует ошибка компиляции в файле fixedMultiStack.java. Это должно быть

throw new FullStackException("ERR: That stack is full!");