// FamilyTree Example // Class Main // Hard code this family tree: // // +-----------John---------------+ // | | | // Arthur Marjorie Randolf // / \ / \ | // / \ / \ | // Jason Katie Barry Jennifer Chloe // | // Walter // // Then print out in depth first order using toString. public class FamilyTree { public static void main(String[] args) { // Create family tree. Person patriarch = new Person("John"); patriarch.addChild(new Person("Arthur")); patriarch.addChild(new Person("Marjorie")); patriarch.addChild(new Person("Randolf")); patriarch.getChild(0).addChild(new Person("Jason")); patriarch.getChild(0).addChild(new Person("Katie")); patriarch.getChild(1).addChild(new Person("Barry")); patriarch.getChild(1).addChild(new Person("Jennifer")); patriarch.getChild(2).addChild(new Person("Chloe")); patriarch.getChild(0).getChild(0). addChild(new Person("Walter")); // Print the names in the family tree in // depth first order using a recursive // algorithm System.out.println(patriarch); } }