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