

/**
 * All Birds can fly.  Therefore they implement the Flyer interface.  Every time
 * a bird flies, its altitude increases by one.
 */
public abstract class Bird extends ZooAnimal implements Flyer {
  protected int altitude;

  /**
   * Reuse superclass constructor.
   */
  public Bird(String name) {
    super(name);
  }

  /**
   * Birds are hungry 40% of the time.
   */
  public boolean isHungry() {
    return nextRandom() < .40;
  }

  /**
   * Must implement fly method from Flyer interface.
   */
  public void fly() {
    System.out.println(name + " is flying");
    altitude++;
  }

  /**
   * Must implement getAltitude method from Flyer interface.
   */
  public int getAltitude() {
    return altitude;
  }
} // Bird