import java.util.*; class Child implements AncTree { String name; int yob; // year-of-birth String eye; // eye-color, e.g. "brown" AncTree ma, pa; // mother, father /** standard constructor */ public Child( String _name, int _yob, String _eye, AncTree _ma, AncTree _pa ) { this.name = _name; this.yob = _yob; this.eye = _eye; this.ma = _ma; this.pa = _pa; } public int size( /* Child this */ ) { return 1 + (this.ma).size() + (this.pa).size(); } public AncTree changeName( /* Child this, */ String name1, String name2 ) { return new Child( ( this.name.equals(name1) ? name2 : this.name ), this.yob, this.eye, (this.ma).changeName(name1,name2), (this.pa).changeName(name1,name2) ); } public List allNames( /* AncTree this */ ) { List result = new ArrayList(); result.addAll( this.ma.allNames() ); result.add( this.name ); result.addAll( this.pa.allNames() ); return result; } /** @Override */ public String toString( /* Child this */ ) { return "new Child" + "( " + "\"" + this.name.toString() + "\"" + ", " + this.yob + ", " + "\"" + this.eye.toString() + "\"" + ", " + this.ma.toString() + ", " + this.pa.toString() + " )"; } public boolean equals( /* Child this, */ Object that ) { if (this==that) { return true; } if (that==null) { return false; } if (this.getClass() != that.getClass()) { return false; } else { Child thatt = (Child)that; return this.name.equals(thatt.name) && this.yob == thatt.yob && this.eye.equals(thatt.eye) && this.ma.equals(thatt.ma) && this.pa.equals(thatt.pa); } } public int hashCode( /* Child this */) { int hashSoFar = 0; hashSoFar *= 31; hashSoFar += name.hashCode(); hashSoFar *= 31; hashSoFar += eye.hashCode(); hashSoFar *= 31; hashSoFar += yob.hashCode(); hashSoFar *= 31; hashSoFar += ma.hashCode(); hashSoFar *= 31; hashSoFar += pa.hashCode(); return hashSoFar; } }