Lab 7

In this lab, we consider a concurrent stack. We start from the following skeleton of a sequential stack. Note that the class Stack does not implement a stack correctly.

/**
 * A stack.  It stores integers.
 *
 * @author
 */
public class Stack {
  private int[] content;
  private int size;
 
  /*
   * The maximal number of integers that can be stored in a stack.
   */
  private final static int CAPACITY = 5;
 
  /**
   * Initializes this stack to be empty.
   */
  public Stack() {
    this.content = new int[Stack.CAPACITY];
    this.size = 0;
  }
 
  /**
   * Pushes the given integer onto this stack.
   *
   * @param value the integer to be pushed onto this stack.
   */
  public void push(int value) {
    this.content[this.size] = value;
    this.size++;
    System.out.printf("Push %d\n", value);
  }
 
  /**
   * Pops the top of this stack and returns the integer.
   *
   * @return the top of this stack.
   */
  public int pop() {
    this.size--;
    int value = this.content[this.size];
    System.out.printf("Pop %d\n", value);
    return value;
  }
}

Implement the following classes.

To receive feedback, submit your code using the submit command:

submit 4315 lab7 <name of class>.java