import java.util.Calendar; //to determine current year

/**
 * Models a Person, including their name and age.
 *
 * @author Zach Tomaszewski
 * @version 11 Mar 2008
 */
public class Person {

  private static final int CURRENT_YEAR = Calendar.getInstance().get(Calendar.YEAR);
  private static int people = 0; //counts the number of Persons created

  //instance variables: every Person has a name and YOB.
  private String name;
  private int yearOfBirth;


  /**
   * Constructs a new Person with the given name and yearOfBirth.
   */
  public Person(String n, int yob) {
    this.name = n;
    this.yearOfBirth = yob;
    people++;  //increment static counter
  }

  /**
   * Constructs a new Person who's year of birth is the current year.
   */
  public Person(String name) {
    //actually calling the other constructor to let it do the work
    this(name, CURRENT_YEAR);
  }


  public String getName() {
    return this.name;
  }

  public int getYearOfBirth() {
    return this.yearOfBirth;
  }

  public void setYearOfBirth(int yob) {
    this.yearOfBirth = yob;
  }

  public int getAge() {
    return CURRENT_YEAR - this.yearOfBirth;
  }

  public String toString() {
    return this.name + " (Born: " + this.yearOfBirth + ").";
  }


  /**
   * Returns the number of Person objects created so far.
   */
  public static int getNumberOfPeople() {
    return Person.people;
  }
}
