// Oefening StackTest, D&D 5, blz 1104,..
import java.util.*;

public class H21_StackTest {
	
	public H21_StackTest() {
		Stack stack = new Stack();
		
		Boolean bool = Boolean.TRUE;
		Character karakter = new Character('€');
		Integer integer = new Integer(21184);
		String string = "Psst";
		
		stack.push(bool);
		printStack(stack);
		stack.push(karakter);
		printStack(stack);
		stack.push(integer);
		printStack(stack);
		stack.push(string);
		printStack(stack);
		
		try {
			Object removedObject = null;
			while(true) {
				removedObject = stack.pop();
				System.out.println("'" + removedObject.toString() + "' popped (= verwijderd)");
				printStack(stack);
			}
		}
		catch (EmptyStackException e) {
			e.printStackTrace();
		}
	}
	
	private void printStack(Stack stack) {
		if (stack.isEmpty())
			System.out.print("'stack' is leeg");
		else {
			System.out.print("'stack' bevat: ");
			Enumeration items = stack.elements();
			
			while (items.hasMoreElements())
				System.out.print(items.nextElement() + " ");
		}
		System.out.println("\n");
	}
	
	public static void main(String args[]) {
		new H21_StackTest();
	}
}
