Lab 2
Due 9:30AM September 17, 2007
- Implement and test a class Item that implements the Comparable
interface and contains two data members: a String and an int. Provide get
and set methods for both data members as well as a method
compareTo. The compareTo method will compare two Items
by comparing the String objects stored in the Items.
- Implement and test a SortedArray class that maintains an array
of Item objects (from question 1) in sorted order. Include the following methods:
- insert - insert takes as input an Item object and places it
in the correct position in the array. If the array is full after the
insertion, the method will also allocate a new array twice the size
of the previous array, copy all elements from the old array to the
new array, and update the reference to the old array appropriately.
This method returns nothing.
- remove - remove takes as input a String object and removes
Item objects containing the String from the array, updating the array appropriately. This method
returns true if Items containing the String were found and removed and false otherwise
.
- find - find takes as input a String and returns the position
of the Item containing the String if one is found and -1 if no items containing the String are stored in the list.
Sami Rollins