import java.util.Scanner;

public class Species
{
  //Instance variables

  private String name = "No name yet";
  private int population = 0;


  //I have 4 obvservers in the field. 
  //Each records their own lastSeenOn date
  private Date[] lastSeenOn = new Date[4];


  //Constructors

  public Species(String n, int p, Date[] d)
  
  {
    name = n;
    if (p >= 0)
      population = p;
    else
      population = 0;

    //lastSeenOn = d; //uh-oh! alias
    for (int i = 0; i < lastSeenOn.length; i++)
    {
      lastSeenOn[i] = d[i]; //uh-oh! alias
      //lastSeenOn[i] = new Date(d[i]);
    }
  }

  public Species ()
  {
    name = "No name yet";
    population = 0;

    for (int i = 0; i < lastSeenOn.length; i++)
    {
      lastSeenOn[i] = new Date();
    }
  }

  public Species(Species other)
  {
    name = other.name;
    population = other.population;

    //lastSeenOn = other.lastSeenOn; //uh-oh! alias
    for (int i = 0; i < lastSeenOn.length; i++)
    {
      //lastSeenOn[i] = d[i]; //uh-oh! alias
      lastSeenOn[i] = new Date(other.lastSeenOn[i]); //use Date copy constructor
    }
  }

  public String toString()
  {
    return "Name: " + name + "Population: " + population + " Date: " + lastSeenOn;
  }


  //Mutators

  //public void setPopulation(int p)//want a way to tell user about failure
  public boolean setPopulation(int p)
  {
    if (p < 0) {
      population = 0;//or maybe just leave population as it was
      return false;
    }

    population = p;
    return true;
  }

  public boolean setLastSeenOn(Date d, int observer)
  {
    //lastSeenOn[observer] = d; //uh-oh! alias
    lastSeenOn[observer] = new Date(d);
    return true;
  }


  //Accessors

  public String getName()
  {
      return name; 
  }

  public int getPopulation() 
  { 
      return population; 
  }

  //public Date getLastSeenOn(int observer) 
  //{ return lastSeenOn;}//uh-oh! data security problem! 
  public Date getLastSeenOn(int observer) 
  {
    return new Date(lastSeenOn[observer]);
  }

  //want a method to get ALL last seen on dates--overload
  public Date[] getLastSeenOn()
  {
    //return lastSeenOn; //uh-oh! data security problem!
    Date [] d = new Date[lastSeenOn.length];
    for (int i=0; i<d.length; i++) {
      d[i] = new Date(lastSeenOn[i]);
    }
    return d;
  }


  public static void main(String[] args)

  {
    Date d = new Date(1,31,2005);
    Date[] da = new Date[4];
    for (int i=0; i<da.length; i++) {
      da[i] = d;
    }
    int mypop = 3000;
    Species s1 = new Species("Bat", mypop, da);
    System.out.println("Three param constructor: " + s1.toString());

    //make sure we avoided aliasing
    d.setDate(5,20,2001);
    System.out.println("My cat's birthday is: " + d.toString());
    //this next print should show that species' lastSeen is still
    // 1/31/05, NOT 5/20/01
    System.out.println("Checking that we didn't create an alias for the date:" + s1.toString());
  }
}

