
public class IteratorDemo
{
    public static void main(String[] args)
    {
        LinkedListOfEmployees list = new LinkedListOfEmployees( );
        list.add(new Employee("Sandy Hair", new Date(1, 1, 2000)));
        list.add(new HourlyEmployee(
                "Dusty Rhodes", new Date(2, 2, 2001), 25.00, 40.0));
        list.add(new SalariedEmployee(
                      "Chuck Steak", new Date(3, 3, 2002), 80000));

        LinkedListOfEmployees.EmployeeIterator i = list.iterator();

        System.out.println("List contains:");
        while(i.hasNext())
            System.out.println(i.next());
        System.out.println();

        i.restart();
        i.next();
        System.out.println("Will delete node for "
                                      + (i.peek()).getName());
        i.delete();

        System.out.println("List now contains:");
        i.restart();
        while(i.hasNext())
            System.out.println(i.next());
        System.out.println();

        i.restart();
        i.next();
        System.out.println("Will add one node before "
                            + (i.peek()).getName());
        i.add(new Employee(
                      "Natelie Dressed", new Date(4, 4, 2003)));
        System.out.println("List now contains:");
        i.restart();
        while(i.hasNext())
            System.out.println(i.next());

        System.out.println();
        System.out.println("Changing all names to Kilroy.");
        i.restart();
        while(i.hasNext())
            (i.next()).setName("Kilroy");
        System.out.println();

        System.out.println("List now contains:");
        i.restart();
        while(i.hasNext())
            System.out.println(i.next());
        System.out.println();
    }
}