
/* Implements the Stack data structure. */

public class Stack {

  protected int size;
  private int capacity;
  private String[] stackArray;

  public Stack(int capacity) {
    this.capacity = capacity;
    this.stackArray = new String[capacity];
  }

  /* Push the new item to the top of the stack. */
  protected void push(String item) {
    if (this.size < this.capacity) {
      this.stackArray[size] = item;
      this.size++;
    }
  }

  /* Pop the item off the top of the stack. */
  protected void pop() {
    if (this.size > 0) {
      this.stackArray[size - 1] = null;
      this.size--;
    }
  }

  /* Determine if the stack is empty. */
  protected boolean isEmpty() {
    return this.size == 0;
  }

  /* Determine if the stack still has space for more elements. */
  protected boolean hasSpace() {
    return this.size < this.capacity;
  }

  /* Show the elements in the stack */
  protected void displayStack() {
    for (String item : this.stackArray) {
      if (item != null) {
      System.out.println(item);
      }
    }
  }

}

@@ -426,32 +426,44 @@
 s.size++;%0A    %7D%0A
+    return;%0A
   %7D%0A%0A  /* Pop th
@@ -485,32 +485,46 @@
 top of the stack
+ and return it
 . */%0A  protected
@@ -524,20 +524,22 @@
 otected 
-void
+String
  pop() %7B
@@ -560,24 +560,77 @@
 size %3E 0) %7B%0A
+      String poppedItem = this.stackArray%5Bsize - 1%5D;%0A
       this.s
@@ -676,25 +676,67 @@
 size--;%0A    
-%7D
+  return poppedItem;%0A    %7D%0A    return null;
 %0A  %7D%0A%0A  /* D

Modify Stack pop to return the popped item.