// CSE 143, Winter 2009, Marty Stepp // A StutterIntList is an ArrayIntList with a "stretch factor" so that // when a value is added, many copies of it are actually added to the list. // This is not a very useful class, but we wrote it to practice inheritance. public class StutterIntList extends ArrayIntList { private int stretch; // number of copies of each element to add // Initializes a new empty list with the given stretch factor. // A stretch factor <= 0 will not allow any elements to be added to the list. public StutterIntList(int stretchFactor) { super(); stretch = stretchFactor; } // Initializes a new empty list with the given stretch factor and array capacity. // A stretch factor <= 0 will not allow any elements to be added to the list. public StutterIntList(int stretchFactor, int capacity) { super(capacity); stretch = stretchFactor; } // Adds several copies of the given value to the end of the list. public void add(int value) { for (int i = 1; i <= stretch; i++) { super.add(value); } } // Inserts several copies of the given value at the given index of the list. // Precondition: 0 <= index <= size public void add(int index, int value) { for (int i = 1; i <= stretch; i++) { super.add(index, value); } } // Returns the stretch factor of this list. public int getStretch() { return stretch; } }