class Containter { private Object[] list; private int nextSlot; private static final int DEFAULT_SIZE = 10; private static final double GROWTH_FACTOR = 2.0; private static final String NL = System.getProperty ("line_separator"); public Container() { list = new Object[DEFAULT_SIZE]; nextSlot = 0; } public Container (int size) { list = new Object[size]; nextSlot = 0; } // Add an "insertFirst" method to this container. // It should add the new item at index 0 // Note: Yes, it does need to shift the rest back public boolean insertFirst (Object item) { if (nextSlot == list.length) grow(); for (int index=nextSlot; index > 0; index--) { list[index] = list[index-1]; } list[0] = item; nextSlot++; } public void add (Object item) { if (nextSlot == list.length) grow(); list[nextSlot++] = item; } public boolean contains (Object item) { for (int index=0; index < nextSlot; index++) { if (items[index].equals(item)) return true; } return false; } public boolean remove (Object item) { int index; for (index=0; index < nextSlot; index++) { if (list[index].equals(item)) break; } if (index == nextSlot) return false; for (int hole=index; hole < (nextSlot-1); hole++) { list[hole] = list[hole+1]; list[hole+1] = null; } nextSlot--; } private void grow() { Object[] biggerList = new Object[(int)(GROWTH_FACTOR * list.length)]; for (int index=0; index < nextSlot; index++) biggerList[index] = list[index]; list = biggerList; } public String toString() { String rep = ""; for (int index=0; index < nextSlot; index++) { rep += items[index] + NL; } } }