// Returns the length of the longest name of this Amoeba's children public int longestNameLength() { int maxLengthSeen = myName.length(); for (Amoeba a : myChildren) { maxLengthSeen = Math.max(maxLengthSeen, a.longestNameLength()); } return maxLengthSeen; }
public void printFlat() { if (myName != null) { System.out.println(myName); for (Amoeba a : myChildren) { a.printFlat(); } ; } }
// Add a child if parent name matches an amoeba's name, // or if parentName matches any of the descendents public void addChild(String parentName, String childName) { if (myName.equals(parentName)) { Amoeba child = new Amoeba(childName, this); myChildren.add(child); } else { for (Amoeba a : myChildren) { a.addChild(parentName, childName); } } }
// returns the length of the longest name in the Amoeba Family public int longestNameLength() { if (myRoot != null) { return myRoot.longestNameLength(); } return 0; }
// Print the names of all amoebas in the family. // later you will write print() that has more interesting formatting public void printFlat() { if (myRoot != null) { myRoot.printFlat(); } }
// 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) { if (myRoot != null) { myRoot.addChild(parentName, childName); } }