import java.util.*;

public class AmoebaFamily {
	
	private Amoeba myHead = null;
	
	public AmoebaFamily (String name) {
		myHead = new Amoeba (name, null);
	}
	
	// Add a new amoeba named childName as the youngest child
	// of the amoeba named parentName.
	// Precondition: the amoeba family contains an amoeba named parentName.
	public void addChild (String parentName, String childName) {
		// You supply this code for exercise 1.
	}
	
	// Print the names of all amoebas in the family.
	// Names should appear in preorder, with children's names
	// printed oldest first.
	// Members of the family constructed with the main program above
	// should be printed in the following sequence:
	//	Amos McCoy, mom/dad, me, Mike, Bart, Lisa, Homer, Marge,
	//	Bill, Hilary, Fred, Wilma
	public void print ( ) {
		// You supply this code for exercise 2.
	}
	
	public static void main (String [ ] args) {
		AmoebaFamily family = new AmoebaFamily ("Amos McCoy");
		family.addChild ("Amos McCoy", "mom/dad");
		family.addChild ("mom/dad", "me");
		family.addChild ("mom/dad", "Fred");
		family.addChild ("mom/dad", "Wilma");
		family.addChild ("me", "Mike");
		family.addChild ("me", "Homer");
		family.addChild ("me", "Marge");
		family.addChild ("Mike", "Bart");
		family.addChild ("Mike", "Lisa");
		family.addChild ("Marge", "Bill");
		family.addChild ("Marge", "Hilary");
		System.out.println ("Here's the family:");
		family.print ( );
		System.out.println ("");
		System.out.println ("Here it is again!");
		AmoebaEnumeration enum = family.new AmoebaEnumeration ( );
		while (enum.hasMoreElements ( )) {
			System.out.println (((Amoeba) enum.nextElement ( )));
		}
	}
	
	public class AmoebaEnumeration implements Enumeration {
		// Amoebas in the family are enumerated in preorder,
		// with children enumerated oldest first.
		// Members of the family constructed with the main program above
		// should be enumerated in the following sequence:
		//	Amos McCoy, mom/dad, me, Mike, Bart, Lisa, Homer, Marge,
		//	Bill, Hilary, Fred, Wilma
		// Complete enumeration of a family of n amoebas should take
		// O(n) operations.
		
		// You supply the details of this class for exercises 3 and 4.
	}

	private class Amoeba {

		public String myName;			// amoebaÕs name
		public Amoeba myParent;			// amoebaÕs parent
		public Vector myChildren;		// amoebaÕs children
		
		public Amoeba (String name, Amoeba parent) {
			myName = name;
			myParent = parent;
			myChildren = new Vector ( );
		}
		
		public String toString ( ) {
			return myName;
		}
		
		public Amoeba parent ( ) {
			return myParent;
		}

		// Add an amoeba with the given name as this amoebaÕs youngest child.		
		public void addChild (String childName) {
			Amoeba child = new Amoeba (childName, this);
			myChildren.addElement (child);
		}
	}
}	
