Question: PLS HELP. Have most of my code but keeps having a error. Heres my code for MyArrayList.java: import java.util.NoSuchElementException; public class MyArrayList implements MyList {

PLS HELP.
Have most of my code but keeps having a error.
Heres my code for MyArrayList.java:
import java.util.NoSuchElementException;
public class MyArrayList implements MyList {
private int currentCapacity =8;
private int size =0;
private Object[] storage = new Object[currentCapacity];
public void append(Object o){
if (size == currentCapacity){
makeCapacity(currentCapacity *2);
}
storage[size++]= o;
}
public void insertAt(int index, Object o){
if (index 0|| index > size){
throw new NoSuchElementException("Index out of bounds");
}
if (size == currentCapacity){
makeCapacity(currentCapacity *2);
}
for (int i = size; i > index; i--){
storage[i]= storage[i -1];
}
storage[index]= o;
size++;
}
@Override
public void removeAt(int index){
if (index 0|| index >= size){
throw new NoSuchElementException("Index out of bounds");
}
for (int i = index; i size -1; i++){
storage[i]= storage[i +1];
}
size--;
}
@Override
public Object getAt(int index){
if (index 0|| index >= size){
throw new NoSuchElementException("Index out of bounds");
}
return storage[index];
}
@Override
public int getSize(){
return size;
}
public void makeCapacity(int minCapacity){
if (minCapacity = currentCapacity || minCapacity =8){
return;
}
currentCapacity = minCapacity;
Object[] newStorage = new Object[currentCapacity];
for (int i =0; i size; i++){
newStorage[i]= storage[i];
}
storage = newStorage;
}
public void trimExcess(){
makeCapacity(size);
}
@Override
public MyListIterator getIterator(){
return new MyArrayListIterator();
}
private class MyArrayListIterator implements MyListIterator {
int currentIndex =-1;
@Override
public Object next(){
++currentIndex;
return storage[currentIndex];
}
@Override
public boolean hasNext(){
return currentIndex size -1;
}
}
}
PLS HELP. Have most of my code but keeps having a

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!