import java.util.Iterator;
import java.util.NoSuchElementException;

public class TestIterator {

    public static void main(String[] args) {
        // create the Bag
        Bag<String> bag = new ArrayBag<>();
        bag.add("This");
        bag.add("is");
        bag.add("the");
        bag.add("bag");

        // show the Bag
        System.out.println("Here is the bag: " + bag);
        // create the iterator
        Iterator<String> it = bag.iterator();
        while (it.hasNext()) {
            String word = it.next();
            System.out.println("There is a \"" + word + "\" in the Bag");
        }
        if (it.hasNext()) {
            System.out.println("This is very weird!");
        } else {
            System.out.println("There is nothing more in the Bag");
        }

        // mess around
        bag.add("extended");
        if (it.hasNext()) {
            System.out.println("OK, now there is a \"" + it.next() 
                    + "\" in the Bag");
        } else {
            System.out.println("Didn't notice the extra thing in the bag...");
        }

        // try to go past the end
        try {
            System.out.println("This is no " + it.next() + " in the bag, "
                    + "so this line should NOT get printed!");
            System.out.println("You may be ready for Activity 2");
        } catch (NoSuchElementException nse) {
            System.out.println("Got the expected exception");
        }
    }

}
