public class Chicken implements Comparable<Chicken> 
{
  private String name;
  private int age;
  private double weight;

  public Chicken(String n, int a, double w) throws ChickenException
  {
    this.name = n;
    if(a > 0)
    {
      this.age = a;
    }
    else
    {
      throw new ChickenException("Chickens age must be > 0");
    }
    if(w > 0.0)
    {
      this.weight = w;
    }
    else
    {
      throw new ChickenException("No floating chickens");
    }
  }

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

  public int getAge()
  {
    return this.age;
  }

  public double getWeight()
  {
    return this.weight;
  }

  public void setAge(int a) throws ChickenException
  {
    if(this.age < a)
    {
      this.age = a;
    }
    else
    {
      throw new ChickenException("Chickens do not age backwards.");
    }
  }

  public void setWeight(double w) throws ChickenException
  {
    if(w > 0.0)
    {
      this.weight = w;
    }
    else
    {
      throw new ChickenException("No floating chickens.");
    }
  }

  public void fly()
  {
    System.out.println(this.name + " flaps her wings and manages to fly a few feet.");
  }

  public void cluck()
  {
    System.out.println(this.name + " says buck buck buck.");
  }

  public void layEgg()
  {
    System.out.println(this.name + " lays an egg.");
  }

  public String toString()
  {
    return "A Chicken-- Name:" + this.name + " Age:" + this.age + " Weight:" + this.weight;
  }

  public int compareTo(Chicken rhs)
  {
    if(this.weight > rhs.weight)
      return 1;
    else if(this.weight < rhs.weight)
      return -1;
    else //same weight
      return 0;
  }

  public static void main(String args[]) throws Exception
  {
    Chicken c1 = null;
    Chicken c2 = null;
    Chicken bad = null;
    
    try
    {
      c1 = new Chicken("Henrietta", 1, 1.5);
      c2 = new Chicken("Eggletina", 2, 2.5);
    }
    catch (ChickenException e)
    {
      System.out.println(e);
    }
    System.out.println(c1);
    System.out.println(c2);
    int size = c1.compareTo(c2);
    int size2 = c2.compareTo(c1);
    int size3 = c1.compareTo(c1);
    System.out.println(size + " " + size2 + " " + size3);
    try
    {
      bad = new Chicken("Bad", -1, 2.5);
    }
    catch (ChickenException e)
    {
      System.out.println(e);
    }
  }
}

/*
int a;//   1066 |?| <-a
a = 10;//  1066 |10| <-a

Chicken c1; //  1666 |?| <-c1
c1 = new Chicken("Henrietta", 1, 1.5);

----------------------------------  My new chicken
1776    |"Henrietta"| <-c1.name 
1777    | 1         | <-c1.age
1777    | 1.5       | <c1.weight 
----------------------------------
1666 |1777| <-c1  //c1 contains the address of the new chicken
*/
