import java.lang.*;

public class Kangaroo {
    
    static final int MALE = 0;
    static final int FEMALE = 1;
    static final double [] FERTILITY = {0, 0.25, 0.5, 0.65, 0.75, 0.9, 0.95, 0.95, 0.95, 0.9, 0.6, 0.4, 0.2, 0};
    static final double [] MORTALITY = {0.45, 0.4, 0.3, 0.3, 0.25, 0.25, 0.25, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0};
    
    private int _age = 0;
    final int gender = (Math.random () < 0.5) ? Kangaroo.MALE : Kangaroo.FEMALE;
    
    /**
     * This is the default constructor - which does nothing, since all variable
     * initialization is handled in the declaration statements, above.
     */
    public Kangaroo () {
    }
    
    /** 
     * Here is an alternative constructor, used when we want to create a 
     * Kangaroo of a specified age (rather than a new-born kangaroo, which has
     * an age of 0.
     */
    public Kangaroo (int initialAge) {
        this._age = initialAge;
    }
    
    public int getAge () {
        return this._age;
    }
    
    public void age () {
        this._age++;
    }

    /**
     * We have added a gender condition to this method; kangaroos only bear
     * young if they are female.
     */
    public Kangaroo breed () {
        if ((this.gender == FEMALE) && (this._age < FERTILITY.length) && (Math.random () < FERTILITY [this._age])) {
            return new Kangaroo ();
        }
        return null;
    }
    
    public boolean survive () {
        if ((this._age < MORTALITY.length) && (Math.random () >= MORTALITY [this._age])) {
            return true;
        }
        return false;
    }
}
