
class Practicestack {

        public static void main(String[] args) {
            Stackx newStack = new Stackx(5);
            newStack.push("redShirt");
            newStack.push("greenShirt");
            newStack.push("yellowPants");
            newStack.push("purpleSocks");
            newStack.push("pinkSocks");
            newStack.peek();

//Display the Full Stack
            newStack.display();
//Test removing a value using pop method
            newStack.pop();

            newStack.display();
          }
}
class Stackx {
        private int maxSize; //number of items in stack
        private String[] stackArray;
        private int top; // top of stack

    public Stackx(int arraySize) {
        maxSize = arraySize;
        stackArray = new String[maxSize];
        top = -1;
    }

    public void push(String a) {    //put value on top of stack
        if (top == maxSize - 1) 
        {
            System.out.println("Stack is full");
        } else {

            top = top + 1;
            stackArray[top] = a;
        }
    }

    public String pop() {              //take item from top of stack
        if (!isEmpty())
            return stackArray[top--]; // access item, decrement top
        else {
            System.out.println("Stack is Empty");
            throw null;
        }
    }

    public String peek()               //peek at the top of the stack
    {
        return stackArray[top];
    }

    public boolean isEmpty() {      //true if stack is empty
        return top == -1;
    }

    public void display() {

        for (int i = 0; i <= top; i++) {
            System.out.print(stackArray[i] + " ");
        }
        System.out.println();
    }
} // End class stackx