Example #1
10
 // 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;
 }
Example #2
0
 public void printFlat() {
   if (myName != null) {
     System.out.println(myName);
     for (Amoeba a : myChildren) {
       a.printFlat();
     }
     ;
   }
 }
Example #3
0
 // 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);
     }
   }
 }
Example #4
0
 // returns the length of the longest name in the Amoeba Family
 public int longestNameLength() {
   if (myRoot != null) {
     return myRoot.longestNameLength();
   }
   return 0;
 }
Example #5
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();
   }
 }
Example #6
0
 // 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);
   }
 }