public class Chicken
{
  private String name;
  private int age;
  private char gender;
  private double weight;

  public Chicken(String n, int a, char g, double w)
  {
    this.name = n;
    if(a > 0 &&  a <= 5)
    {
      this.age = a;
    }
    else
    {
      System.err.println("Illegal age " + a);
      System.exit(1);
    }
    
    if(g == 'f')
    {
      g = 'F';
    }
    else if (g == 'm')
    {
      g = 'M';
    }
    if (g != 'F' && g != 'M')
    {
      System.err.println("Illegal gender");
      System.exit(1);
    }
    else
    {
      this.gender = g;
    }
    this.setWeight(w);
  }

  public Chicken(Chicken c)
  {
    this.name = c.name;
    this.age = c.age;
    this.gender = c.gender;
    this.weight = c.weight; 
  }

  public String toString()
  {
    String retval = "";
    retval = retval + "This is a ";
    if(this.gender == 'M')
      retval += "rooster ";
    else
      retval += "hen "; 
    retval += "named " + this.name;
    retval += " It\'s age is " + this.age;
    retval += " It\'s weight is " + this.weight;
    return retval;
  }

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

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

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

  public void setWeight(double w)
  {
    if(w <= 0)
    {
      System.err.println("No floating chickens!");
      System.exit(1);
    }
    else
    {
      this.weight = w;
    }
  }

  public void fly()
  {
    System.out.println(this.name + " flaps its wings and attempts to fly.");
  }

  public void scratch()
  {
    System.out.println(this.name + "scratches the dirt and finds a tasty beetle.");
  }
  
  public void layEgg()
  {
    if(this.gender == 'F')
    {
      System.out.println(this.name + "Lays an egg.");
    }
    else
    {
      System.out.println(this.name + "Attempts to lay an egg, but is not able because he is a rooster.");
    }
  }


  public static void main(String args[])
  {
    int temp1 = 12;
    int temp2 = temp1;
    System.out.println("temp1 = " + temp1 + " temp2 = " + temp2);
    temp2 = 85;
    System.out.println("temp1 = " + temp1 + " temp2 = " + temp2);
    Chicken c1 = new Chicken("Henrietta", 2, 'F', 2.3);
    Chicken c2 = new Chicken(c1);
    System.out.println("c1 weight = " + c1.getWeight() + " c2.weight =" + c2.getWeight());
    c2.setWeight(4.0); 
    System.out.println("c1 weight = " + c1.getWeight() + " c2.weight =" + c2.getWeight());

    System.out.println(c1);
    System.out.println(c2);
  }
}

