import java.util.Scanner; import java.util.ArrayList; import java.lang.Math; public class classestemplate { private static final int PARTNER = 0; private static final int MOTHER = 1; private static final int FATHER = 2; private static final int NAME = 3; private static final int PERSON_SIZE = 4; private static ArrayList persons = new ArrayList(); private static ArrayList names = new ArrayList(); public static void main(String[] args) { // Meet Bob! int[] bob = new int[PERSON_SIZE]; bob[MOTHER] = -1; // Bob's mother is not in this program bob[FATHER] = -1; // Bob's father is not in this program int bobsIndex = persons.size(); // Find Bob's index number persons.add(bob); // Register Bob bob[NAME] = names.size(); // Find Bob's name's index number names.add("Bob"); // Meet Mary! int[] mary = new int[PERSON_SIZE]; mary[MOTHER] = -1; // Mary's mother is not in this program mary[FATHER] = -1; // Mary's father is not in this program int marysIndex = persons.size(); // Find Mary's index number persons.add(mary); // Register Mary mary[NAME] = names.size(); // Find Mary's name's index number names.add("Mary"); // Bob and Mary are married! bob[PARTNER] = marysIndex; mary[PARTNER] = bobIndex; // Meet their child Tim! int[] tim = new int[PERSON_SIZE]; tim[PARTNER] = -1; // Tim is not married tim[MOTHER] = marysIndex; tim[FATHER] = bobIndex; int timsIndex = persons.size(); // Find Tim's index number persons.add(tim); // Register Tim tim[NAME] = names.size(); // Find Tims's name's index number names.add("Tim"); // If we want Tim's mother, we do this: int[] timsMother = persons[tim[MOTHER]]; // If we want her partner, we do this: int[] timsMothersPartner = persons[timsMother[PARTNER]]; // Note that timsMother == mary and timsMothersPartner == bob string timsMothersName = names[timsMother[NAME]]; string timsMothersPartnersName = names[timsMothersPartner[NAME]]; // Remember to check for -1 entries } }