Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I agree please use something like arraylist. <a href="http://docs.oracle.com/javase/1.4.2/docs/api/java/util/Stack.html" rel="nofollow">http://docs.oracle.com/javase/1.4.2/docs/api/java/util/Stack.html</a> Is already implemented class but i fixed your code in case you are new to java and just are playing around with it. Did not check logic but hopefully syntax correction helps </p> <pre><code> package Temp; public class GeneralStack { int[] stack; //not sure how to declare this private int count; private int maxCapacity; private static final int DEFAULT_CAPACITY = 100; //default constructor public GeneralStack() { stack = new int[DEFAULT_CAPACITY]; count = 0; maxCapacity = this.DEFAULT_CAPACITY; } //alternate constructor public GeneralStack (int maxCapacity) { stack = new int[maxCapacity]; count = 0; this.maxCapacity = maxCapacity; } //accessor getCount public int getCount () { return count; } //accessor isEmpty public boolean isEmpty () { boolean isEmpty=false; if (count == 0); { isEmpty=true; } return isEmpty; } //accessor isFull public boolean isFull () { boolean isFull=false; if (count == maxCapacity); { isFull=true; } return isFull; } //mutator push public void push (int value) { if (isFull ()) { throw new IllegalArgumentException("Stack is full"); } else { stack[count] = value; //not sure how to assign value to the stack count++; } } // you cant return value from void function so changing it to int return you can ignore a return value public int pop () { int topVal = topVal(); count = count-1; return topVal; } //accessor top public int topVal () { int topVal; if (isEmpty()) { throw new IllegalArgumentException("Stack is empty"); } else { topVal=stack[count-1]; } return topVal; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload