734
public abstract voiddelete(String item);
public voidresetList() // Prepare for iteration
{
currentPos = 0 ;
}
publicString getNextItem() // Return an unvisited item
{
String next = listItems[currentPos];
if(currentPos == numItems- 1 )
currentPos = 0 ;
else
currentPos++;
returnnext;
}
}
b.The only design changes are in the name of the class and the documentation
on the insertmethod.
c. public classUnsortedListWithDuplicates extendsListWithDuplicates
{
publicUnsortedListWithDuplicates()
{
super();
}
publicUnsortedListWithDuplicates(intmaxItems)
{
super(maxItems);
}
public booleanisThere(String item)
// Return true if item is in the list
{
intindex = 0 ;
while(index < numItems && listItems[index].compareTo(item) != 0 )
index++;
return(index < numItems);
}
public voidinsert(String item)
// If the list is not full, put item in the last position in the list;
// otherwise, list is unchanged