CSC 313: Data Structures in Java
Autumn 2002
Inidividual Assignment 4
Object Collections and Iterators
Due Wednesday October 23 before 11:30pm
In this course, we study the SimpleCollection class and the SimpleIterator class. The
SimpleCollection class holds a collection of Objects and
SimpleIterator provides an iterator for it. In this assignment you
will document and expand the functionality of both of these classes.
For the SimpleCollection class, you will add the following functionalities:
- Modify the add method so that the capacity of the array is
automatically doubled whenever more capacity is needed.
- Provide a size method that returns how many objects are currently
stored in the collection.
- Provide a countOccurrences method that takes an object as an
argument and returns a count of how many times that object appears (as
defined by the equals method) in the collection.
- Provide a containsAll method that takes a SimpleCollection object
as an argument and returns true if every object in the passed
collection is present in the collection. Otherwise, the method
returns false.
For the SimpleIterator class, you will implement one additional method:
- The remove method, which deletes the object that was most recently
retrieved from the next method. The method should throw an
IllegalStateException if the next method has not yet been called, or
the remove method has already been called after the last call to the
next method. Hint: add a boolean instance variable to your class
that keeps track of whether the current object has been deleted.
Within the main method of the SimpleIterator class, provide additional
test code that demonstrates that all of the methods in your classes
work correctly. Make sure you fully document your classes according
to the standards of the text and javadoc.
Submission
Before the due date and time, you should submit the following
files through the submission
Web page:
- Your version of SimpleCollection.java.
- Your version of SimpleIterator.java.