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 ;
private int size ;
private Object storage new ObjectcurrentCapacity;
public void appendObject o
if size currentCapacity
makeCapacitycurrentCapacity ;
storagesize o;
public void insertAtint index, Object o
if index index size
throw new NoSuchElementExceptionIndex out of bounds";
if size currentCapacity
makeCapacitycurrentCapacity ;
for int i size; i index; i
storagei storagei ;
storageindex o;
size;
@Override
public void removeAtint index
if index index size
throw new NoSuchElementExceptionIndex out of bounds";
for int i index; i size ; i
storagei storagei ;
size;
@Override
public Object getAtint index
if index index size
throw new NoSuchElementExceptionIndex out of bounds";
return storageindex;
@Override
public int getSize
return size;
public void makeCapacityint minCapacity
if minCapacity currentCapacity minCapacity
return;
currentCapacity minCapacity;
Object newStorage new ObjectcurrentCapacity;
for int i ; i size; i
newStoragei storagei;
storage newStorage;
public void trimExcess
makeCapacitysize;
@Override
public MyListIterator getIterator
return new MyArrayListIterator;
private class MyArrayListIterator implements MyListIterator
int currentIndex ;
@Override
public Object next
currentIndex;
return storagecurrentIndex;
@Override
public boolean hasNext
return currentIndex size ;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
