CSE143 Section #2 Problems 4. Below is a "bad" version of the ArrayIntList. It has mostly the same functionality as the version discussed in lecture, but it has poor style. Approximately half of the points for each programming assignment in this class will be devoted to style issues, so it is important to understand style issues. What is bad about this version? // Stuart Reges (my name is Elroy Jetson) // This is the ArrayIntList class. import java.util.*; public class ArrayIntList { int[] elementData; // element data int size; // size int capacity; // capacity public static int defaultCapacity = 100; public ArrayIntList() { elementData = new int[100]; size = 0; capacity = 100; } // capacity should be not be negative public ArrayIntList(int capacity) { if (capacity < 0) { throw new IllegalArgumentException(); } else { elementData = new int[capacity]; size = 0; this.capacity = capacity; } } public int size() { return size; } // pre : 0 <= index < size() (throws exception if not) public int get(int index) { if (index < 0 || index >= size) { throw new IndexOutOfBoundsException(); } for (int i = 0; i < size; i++) { if (i == index) { return elementData[i]; } } return 0; } public String toString() { if(size==0) { return"[]"; } else { String result="["+elementData[0]; for(int i=1;i= 0; i--) { if (elementData[i] == value) { count++; } } if (count == 0) { return false; } else { return true; } } // returns the position of the given value in the array, only checking up // to the current size public int indexOf(int value) { int index = 0; for (int i = size - 1; i >= 0; i--) { if (elementData[i] == value) { index = i; } } if (elementData[index] == value) { return index; } else { return -1; } } // pre : size() < capacity (throws IllegalStateException if not) // post: appends the value to the end of the list public void add(int value) { if (size > capacity - 1) { throw new IllegalStateException(); } elementData[size] = value; size++; } // pre : size() < capacity (throws IllegalStateException if not) && // 0 <= index <= size() (throws IndexOutOfBoundsException if not) // post: inserts the value at the index public void add(int index, int value) { for (int i = size; i >= index; i--) { if (index < 0 || index > size) { throw new IndexOutOfBoundsException(); } else if (size > capacity - 1) { throw new IllegalStateException(); } else if (i > index) { elementData[i] = elementData[i - 1]; } else { elementData[i] = value; size++; } } } // post: returns the capacity of the list public int capacity() { return capacity; } // pre : 0 <= index < size() (throws IndexOutOfBoundsException if not) // post: removes value at the index and decreases the size by 1 public void remove(int index) { if (index < 0 || index >= size) { throw new IndexOutOfBoundsException(); } for (int i = index; i < size - 1; i++) { elementData[i] = elementData[i + 1]; } size--; } // appends values to the end of the list public void addAll(ArrayIntList other) { int[] data = Arrays.copyOf(elementData, size + other.size); while (other.size() > 0) { data[size++] = other.elementData[0]; other.remove(0); } elementData = data; } }