// // Supporting material for lecture 14 // - private static variables (population/pop) // public class Person { private String firstName; private String surName; private int age; private Person spouse; private static int pop = 0; // population public Person(String firstName,String surName,int age){ this.firstName = firstName; this.surName = surName; this.age = age; spouse = null; pop++; } public Person(String firstName,String surName){ this.firstName = firstName; this.surName = surName; this.age = 0; spouse = null; pop++; } public String toString(){ String s = firstName + " " + surName + " " + " age " + age; if (spouse != null) s = s + " married to " + spouse.firstName; return s; } public boolean isMarried(){return spouse != null;} public int getAge(){return age;} public String getName(){return firstName + " " + surName;} public void marry(Person x){this.spouse = x;x.spouse = this;} public int getPop(){return pop;} // get population } // // NOTES // - we have 2 constructors // - naming convention of Classes, instance variables, methods such as toString, etc // - this // - null !!! // // Exercise: // Make instance variables and appropriate methods so that // we can make y a father of x, and z the mother of x // also so that we can access father and grandfather of x // Ultimately we have a family tree (or is it a tree?) //