edu.colorado.simulations
Class Animal

java.lang.Object
  extended by edu.colorado.simulations.Organism
      extended by edu.colorado.simulations.Animal
Direct Known Subclasses:
Herbivore

public class Animal
extends Organism

An Animal is an Organism with extra methods that deal with eating.

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

See Also:
Organism, Herbivore, Plant

Constructor Summary
Animal(double initSize, double initRate, double initNeed)
          Construct an Animal with a specified size, growth rate, and weekly eating need.
 
Method Summary
 void eat(double amount)
          Have this Animal eat a given amount of food.
 double getNeed()
          Determine the amount of food that this Animal needs each week.
 void setNeed(double newNeed)
          Set the current growth weekly food requirement of this Animal.
 void simulateWeek()
          Simulate the passage of one week in the life of this Animal.
 double stillNeed()
          Determine the amount of food that this Animal still needs to survive this week.
 
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

Animal

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

Parameters:
initSize - the initial size of this Animal, in ounces
initRate - the initial growth rate of this Animal, 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 Animal has been initialized. The value returned from getSize() is now initSize, the value returned from getRate() is now initRate, and this Animal 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

eat

public void eat(double amount)
Have this Animal eat a given amount of food.

Parameters:
amount - the amount of food for this Animal to eat (in ounces)
Precondition:
amount >= 0.
Postcondition:
The given amount (in ounces) has been added to the amount of food that this Animal has eaten this week. throw IllegalArgumentException Indicates that amount is negative.

getNeed

public double getNeed()
Determine the amount of food that this Animal needs each week.

Returns:
the total amount of food that this Animal needs to survive one week (measured in ounces)

setNeed

public void setNeed(double newNeed)
Set the current growth weekly food requirement of this Animal.

Parameters:
newNeed - the new weekly food requirement for this Animal (in ounces)
Precondition:
newNeed >= 0.
Postcondition:
The weekly food requirement for this Animal has been set to newNeed.
Throws:
java.lang.IllegalArgumentException - Indicates that newNeed is negative.

simulateWeek

public void simulateWeek()
Simulate the passage of one week in the life of this Animal.

Overrides:
simulateWeek in class Organism
Parameters:
- - none
Postcondition:
The size of this Animal has been changed by its current growth rate. If the new size is less than or equal to zero, then expire is activated to set both size and growth rate to zero. Also, if this Animal has eaten less than its need over the past week, then expire has been activated.

stillNeed

public double stillNeed()
Determine the amount of food that this Animal still needs to survive this week.

Parameters:
- - none
Returns:
the ounces of food that this Animal still needs to survive this week (which is the total need minus the amount eaten so far).