edu.colorado.simulations
Class Herbivore

java.lang.Object
  extended by edu.colorado.simulations.Organism
      extended by edu.colorado.simulations.Animal
          extended by edu.colorado.simulations.Herbivore

public class Herbivore
extends Animal

A Herbivore is an Animal with extra methods that allow it to eat Plant objects.

Java Source Code for this class:
http://www.cs.colorado.edu/~main/edu/colorado/simulations/Herbivore.java

See Also:
Animal, Plant

Constructor Summary
Herbivore(double initSize, double initRate, double initNeed)
          Construct an Herbivore with a specified size, growth rate, and weekly eating need.
 
Method Summary
 void nibble(Plant meal)
          Have this Herbivore eat part of a Plant.
 
Methods inherited from class edu.colorado.simulations.Animal
eat, getNeed, setNeed, simulateWeek, stillNeed
 
Methods inherited from class edu.colorado.simulations.Organism
alterSize, expire, getRate, getSize, isAlive, setRate
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Herbivore

public Herbivore(double initSize,
                 double initRate,
                 double initNeed)
Construct an Herbivore with a specified size, growth rate, and weekly eating need.

Parameters:
initSize - the initial size of this Herbivore, in ounces
initRate - the initial growth rate of this Herbivore, in ounces
initNeed - the initial weekly eating requirement of this Animal, in ounces per week
Precondition:
initSize >= 0 and initNeed >= 0. Also, if initSize is zero, then initRate must also be zero.
Postcondition:
This Herbivore has been initialized. The value returned from getSize() is now initSize, the value returned from getRate() is now initRate, and this Herbivore must eat at least initNeed ounces of food each week to survive.
Throws:
java.lang.IllegalArgumentException - Indicates that initSize, initRate, or initNeed violates the precondition.
Method Detail

nibble

public void nibble(Plant meal)
Have this Herbivore eat part of a Plant.

Parameters:
meal - the Plant that will be partly eaten
Postcondition:
Part of the Plant has been eaten by this Herbivore, by activating both eat(amount) and meal.nibbledOn(amount). The amount is usually half of the Plant, but it will not be more than 10% of this Herbivore’s weekly need nor more than the amount that this Herbivore still needs to eat to survive this week.