/* * Kyle Pierce * CSE 143 * * Class ArrayIntList is used to store an ordered sequence of integers */ public class ArrayIntList { private int[] elementData; // all the numbers in the list private int size; // how many numbers a client thinks there are public static final int DEFAULT_CAPACITY = 100; // post: initializes an ArrayIntList of default capacity public ArrayIntList() { elementData = new int[DEFAULT_CAPACITY]; size = 0; } // post: returns the current size of this list public int size() { return size; } // pre: this list has enough room for another number // post: adds the given num at the end of the list public void add(int num) { elementData[size] = num; size++; } // post: returns a bracketed, comma-separated String of all // the numbers in this list public String toString() { if (size == 0) { return "[]"; } else { String result = "[" + elementData[0]; for (int i = 1; i < size; i++) { result += ", " + elementData[i]; } result += "]"; return result; } } }