/home/caleb/ASDV-Java/Semester 2/Assignments/MP5_CalebFontenot/src/main/java/com/calebfontenot/mp5_calebfontenot/MyStack.java
/*
 * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
 * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
 */
package com.calebfontenot.mp5_calebfontenot;

/**
 *
 * @author caleb
 */
import java.util.ArrayList;

public class MyStack implements Cloneable {
  private ArrayList<Object> list = new ArrayList<>();

  public boolean isEmpty() {
    return list.isEmpty();
  }

  public int getSize() {
    return list.size();
  }

  public Object peek() {
    return list.get(getSize() - 1);
  }

  public Object pop() {
    Object o = list.get(getSize() - 1);
    list.remove(getSize() - 1);
    return o;
  }

  public void push(Object o) {
    list.add(o);
  }

  @Override /** Override the toString in the Object class */
  public String toString() {
    return "stack: " + list.toString();
  }
  
  @Override
 public Object clone() throws CloneNotSupportedException {
      MyStack clonedStack = (MyStack) super.clone();
      ArrayList<Object> newList = new ArrayList<>(list);
      clonedStack.list = newList;
      return clonedStack;
  }
  
    public static void main(String[] args) throws CloneNotSupportedException {
        MyStack stack = new MyStack();
        final int STACK_SIZE = 50;
        for (int i = 0; i < STACK_SIZE; ++i) {
            stack.push(i + 1); // Fill Stack with sequential numbers.
            //System.out.println(stack.peek());
        }
        System.out.println(stack.peek());
        MyStack clonedStack = (MyStack) stack.clone();
        System.out.println(clonedStack.peek());
    }
}