/** Species models a biological species, keeping track of the number
 *  of individuals.
 */
public class Species{
  // how many are there?  What's this species called?
  // What territory does it inhabit (this variable is
  // possibly not set.
  private int population;
  private String name, territory;

  // How many Species are there?  This information is static:
  // there is one copy for the entire Species class.  Although
  // the default value of a static variable is 0, we can
  // explicitly initialize it to 0.
  private static int count= 0;

  // getCount: return the number of species there are
  public static int getCount() {
    return count;
  }

  /** construct a species with name n and population num.
   *  This sort of makes setPopulation() and setName()
   *  redundant.  Also, increment the number of Species by
   *  one.
   */
  public Species(int num, String n) {
    population= num;
    name= n;
    count= count + 1;
  }

  /** setTerritory: set this species' territory to t
   */
  public void setTerritory(String t) {
    territory= t;
  }

  /** getPopulation returns the number of individuals current
   *  in this Species.
   */
  public int getPopulation(){
    return population;
  }

  /** setPopulation makes this Species have population num.
   */
  public void setPopulation(int num){
    population = num;
  }

  /** setName: call this species n
   */ 
  public void setName(String n) {
    name = n;
  }

  /** getName: return this species' name
   */
  public String getName() {
    return name;
  }

  /** breed: increase this species' population by 1
   */
  public void breed() {
    population = population + 1;
  }

  /** dieOff: decrease this species' population by 1
   */
  public void dieOff() {
    population = population - 1;
  }

  /** toString: return an informative String about this
   *  this species.
   */
  public String toString() {
    String result= "Species: " + name;
    result= result + " has " + getPopulation();
    result= result + " members.\n";
    if (territory != null) {
      result= result + "\nterritory: " + territory;
    }
    return result;
  }

  /** equals: return true if this species has the
   *  same name, population, and territory as the
   *  other species.  Be careful to test other to see
   *  whether it is null before accessing its fields.
   *  Also, check whether territory is null.
   */
  public boolean equals(Species other) {
    return other != null && // this species never equal to a null one
      name.equals(other.name) && // same name
      population == other.population && // same population
      (territory != null && territory.equals(other.territory) ||
        other.territory == null); // territories the same
  }
}


  

