// Person.java // // public class Person { // Constant private static final int MaxChildren = 20; // Fields private String firstName, lastName; private Sexes sex; private Person father; private Person mother; private int numChildren = 0; private Person[] children; // Constructor public Person(String f, String l, Sexes s) { firstName = f; lastName = l; sex = s; numChildren = 0; children = new Person[MaxChildren]; } // Methods public String getFirstName() { return firstName; } public String getLastName() { return lastName; } public Person getFather() { return father;} public Person getMother() { return mother;} public Person[] getChildren() { return children;} public int getNumChildren() { return numChildren;} public Sexes getSex() { return sex;} public String toString() { return "< Person " + firstName + " " + lastName + ">"; } // Setter. When you call setParent(P), P gets marked as the appropriate // parent of this, and this gets added as a child of P. public void setParent(Person P) { if (P.numChildren < MaxChildren) { // Note that if P has already has MaxChildren, then nothing happens P.children[P.numChildren] = this; P.numChildren = P.numChildren + 1; if (P.sex == Sexes.Male) father = P; else mother = P; } } // end SetParent } // end Person