import java.io.*; public class Person { // max # of people in database. private final static int maxN = 100; // folks[0..n] are people in database. private static Person[] folks = new Person[maxN]; private static int n = 0; private String name; // person's name. // relationships with other persons. private boolean male; // person's maleness private Person mom; // person's mother private Person dad; // person's father private Person kid; // person's youngest child private Person other; // person's significant other private Person sibling; // person's next older sibling // Construct person named s of maleness m. public Person(String s, boolean m) { name = s; male = m; // check if there are too many people in the database if ( n >= maxN ) System.out.println("over limit"); else { folks[n] = this; n++; } } // # of people in database. public static int numberOfPeople() { return n; } // i-th person in database. public static Person intToPerson(int i) { if (i < 0 || i >= n) return null; else return folks[i]; } // string representation of a person. public String toString() { String result; result = "name:"+ name; if (male) result = result + " sex:male"; else result = result + " sex:female"; if (mom != null ) result = result + " mom:" + mom.name; if (dad != null ) result = result + " dad:" + dad.name; if (other != null) result = result + " other:" + other.name; result = result + " kids:"; if (kid == null) result = result + " none"; else { Person p = kid; while ( p != null ){ result = result + " " + p.name; p = p.sibling; } } return result; } // create a child of mom and dad with name s and maleness m. public static void child(Person mom, Person dad, String s, boolean m) { Person child = new Person(s, m); child.mom = mom; child.dad = dad; child.sibling = mom.kid; dad.kid = child; mom.kid = child; } // marry persons p1 and p2. public static void marry(Person p1, Person p2) { p1.other = p2; p2.other = p1; } // field accessors. public String name() { return name; } public boolean male() { return male; } public Person other() { return other; } }