This file shows one example of running the program TestIterator.

Recall that the order that the iterator goes thru the Bag's contents is irrelevant. What's important is that all items from the Bag get visited by the iterator exactly once. It's also important that using the iterator's remove method doesn't change that: every item gets visited exacly once.

Return to assignment description

Sample Output

=== Parts 1 & 2 === Here is the bag: [bag, the, is, This] There is a "bag" in the bag There is a "the" in the bag There is a "is" in the bag There is a "This" in the bag There is nothing more in the bag Good! You noticed that change! Good! You noticed that change! === Part 3 === The bag is: [50, 42, 30, 20, 10] The first call to next returns 50 The second call to next returns 42 I will try to remove that. Good. That seems to have worked. The next item should be 30. Good! There should be two items remaining: 20 10 The bag is now: [50, 30, 20, 10] === Part 4 === The bag is [30.3, 20.2, 10.1] Testing remove before next Good! correct exception thrown Testing remove after remove Good! correct exception thrown There should be two items remaining: 20.2 10.1 The bag should now be empty: [] === Part 5 === Here is the bag: [before, gone, has, one, no, where, go, boldly, to] Removing words 'go' 'no' 'so' 'to' and 'zo' Bag is now: [one, before, where, gone, boldly, has] Retaining words 'before' 'boldly' 'go' 'sleep' Bag is now: [boldly, before] === Part 6 === Here is the bag: [5, 4, 3, 2, 1] Removing an item using it1 That seems to have worked Advancing using it1 That seemed to work -- got 4 Advancing using it2 Good! Noticed the external change Removing using it2 Good! Noticed the external change Advancing (again) using it1 That seemed to work -- got 3

Return to assignment description