Hello guys, I'm trying to build this DoubleArraySeq program and the addAfter and addBefore methods are not working correctly and I can't figure out why please help

Code Java:

public class DoubleArraySeq implements Cloneable { // Invariant of the DoubleArraySeq class: // 1. The number of elements in the seqeunces is in the instance variable // manyItems. // 2. For an empty sequence (with no elements), we do not care what is // stored in any of data; for a non-empty sequence, the elements of the // sequence are stored in data[0] through data[manyItems-1], and we // don't care what's in the rest of data. // 3. If there is a current element, then it lies in data[currentIndex]; // if there is no current element, then currentIndex equals manyItems. private double[] data; private int manyItems; private int currentIndex; /** * Initialize an empty sequence with an initial capacity of 10. Note that * the addAfter and addBefore methods work efficiently (without needing more * memory) until this capacity is reached. * @param - none * @postcondition * This sequence is empty and has an initial capacity of 10. * @exception OutOfMemoryError * Indicates insufficient memory for: * new double[10]. **/ public DoubleArraySeq( ) { data = new double[10]; manyItems = 0; currentIndex = 0; } /** * Initialize an empty sequence with a specified initial capacity. Note that * the addAfter and addBefore methods work efficiently (without needing more * memory) until this capacity is reached. * @param initialCapacity * the initial capacity of this sequence * @precondition * initialCapacity is non-negative. * @postcondition * This sequence is empty and has the given initial capacity. * @exception IllegalArgumentException * Indicates that initialCapacity is negative. * @exception OutOfMemoryError * Indicates insufficient memory for: * new double[initialCapacity]. **/ public DoubleArraySeq(int initialCapacity) { if (initialCapacity < 0) { throw new IllegalArgumentException("The initialCapacity is negative: " +initialCapacity); } data = new double[initialCapacity]; manyItems = 0; currentIndex = 0; } /** * Add a new element to this sequence, after the current element. * If the new element would take this sequence beyond its current capacity, * then the capacity is increased before adding the new element. * @param element * the new element that is being added * @postcondition * A new copy of the element has been added to this sequence. If there was * a current element, then the new element is placed after the current * element. If there was no current element, then the new element is placed * at the end of the sequence. In all cases, the new element becomes the * new current element of this sequence. * @exception OutOfMemoryError * Indicates insufficient memory for increasing the sequence's capacity. * @note * An attempt to increase the capacity beyond Integer.MAX_VALUE will cause * the sequence to fail with an arithmetic overflow. **/ public void addAfter(double element) { if (manyItems == data.length) { ensureCapacity(manyItems*2 + 1); } if (!isCurrent()) { currentIndex = manyItems; } for (int i = manyItems; i > currentIndex; i--) { data[i] = data[i-1]; } data[currentIndex] = element; manyItems++; currentIndex++; } /** * Add a new element to this sequence, before the current element. * If the new element would take this sequence beyond its current capacity, * then the capacity is increased before adding the new element. * @param element * the new element that is being added * @postcondition * A new copy of the element has been added to this sequence. If there was * a current element, then the new element is placed before the current * element. If there was no current element, then the new element is placed * at the start of the sequence. In all cases, the new element becomes the * new current element of this sequence. * @exception OutOfMemoryError * Indicates insufficient memory for increasing the sequence's capacity. * @note * An attempt to increase the capacity beyond Integer.MAX_VALUE will * cause the sequence to fail with an arithmetic overflow. **/ public void addBefore(double element) { if (manyItems == data.length) {//try to double capacity ensureCapacity(manyItems*2 + 1); } if (!isCurrent()) { currentIndex = 0; } for (int i = manyItems; i > currentIndex; i--) { data[i] = data[i-1]; } data[currentIndex] = element; manyItems++; } }