Question
***** IN JAVA ******* I need the rest of the methods within ListIterator in AList.java to be completed. I have done a few of them
***** IN JAVA *******
I need the rest of the methods within ListIterator in AList.java to be completed. I have done a few of them already to get the ball rolling, I just cannot figure out the rest of them really. Thank you in advance :)
Classes you WILL need:
AList.java
import java.io.Serializable; import java.util.Arrays; import java.util.Iterator; import java.util.ListIterator; import java.util.NoSuchElementException;
/** * Implementation of an array list. In this implementation: * - The list can be resized. * - No null values allowed. */ public class AList
@Override public boolean add(T obj) { add(size, obj); return true; }
@Override public void clear() { list = new Object[capacity]; size = 0; }
@Override public boolean contains(T obj) { return indexOf(obj) != -1; }
@Override public int indexOf(T obj) { for (int i = 0; i < size; i++) { if (list[i].equals(obj)) { return i; } } return -1; }
@Override public boolean isEmpty() { return size == 0; }
@Override public int lastIndexOf(T obj) { for (int i = size-1; i >= 0; i--) { if (list[i].equals(obj)) { return i; } } return -1; }
@Override public T get(int index) { if (index < 0 || index >= size) throw new IndexOutOfBoundsException(); return (T)list[index]; }
@Override public T remove(int index) { T old = get(index); for (int i = index; i < size-1; i++) { list[i] = list[i+1]; } list[--size] = null; return old; } @Override public boolean remove(T obj) { int index = indexOf(obj); if (index < 0) return false; remove(index); return true; }
@Override public T set(int index, T obj) { if (obj == null) throw new NullPointerException(); T old = get(index); list[index] = obj; return old; }
@Override public int size() { return size; }
@Override public Object[] toArray() { Object[] rarr = Arrays.copyOf(list, size); return rarr; } @Override public Iterator
@Override public T next() { if (!hasNext()) throw new NoSuchElementException(); T obj = (T)list[current++]; nextCalled = true; return obj; }
@Override public void remove() { if (!nextCalled) throw new IllegalStateException(); current--; for (int i = current; i < size-1; i++) { list[i] = list[i+1]; } list[--size] = null; nextCalled = false; } }; } // here is where i need the methods to be completed. @Override public ListIterator
@Override public boolean hasNext(){ return nextIndex < size; } @Override public T next() { if (hasNext()){ nextCalled = true; previousCalled = false; T obj = (T)list[nextIndex++]; return obj; } else { throw new NoSuchElementException(); } }
@Override public boolean hasPrevious() { return nextIndex > 0; }
@Override public T previous() { if (hasPrevious()){ nextCalled = false; previousCalled = true; T obj = (T)list[nextIndex--]; return obj; } else { throw new NoSuchElementException(); } }
@Override public int nextIndex() { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. }
@Override public int previousIndex() { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. }
@Override public void remove() { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. }
@Override public void set(T e) { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. }
@Override public void add(T e) { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } }; } private void resize(int newCapacity) { list = Arrays.copyOf(list, newCapacity); capacity = newCapacity; } }
List.java
import java.util.ListIterator;
/** * */ public interface List
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started