|
Here's how we can use the modified Stack and nested Enumerator classes:
package staticNesting;
/**
* Tests the Stack and StackIterator classes
*/
public class StackTest
{
/**
* Main entry point
*/
public static void main(String[] args)
{
Stack aStack = new Stack(10);
for (int i = 0; i < aStack.getMaxStackSize(); i++)
aStack.push(i*i);
Stack.Enumerator enumerator = new Stack.Enumerator(aStack);
while (enumerator.hasMoreElements())
{
int value = (Integer) enumerator.nextElement();
System.out.print(" " + value);
}
System.out.println();
}
}
|
All I had to do was change the two StackEnumerator references to
Stack.Enumerator.
When run, this program outputs the same values as before:
0 1 4 9 16 25 36 49 64 81
|