edu.colorado.simulations
Class Organism

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

public class Organism
extends java.lang.Object

An Organism object simulates a growing organism such as a plant or animal.

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

See Also:
Animal, Plant

Constructor Summary
Organism(double initSize, double initRate)
          Construct an Organism with a specified size and growth rate.
 
Method Summary
 void alterSize(double amount)
          Change the current size of this Organism by a given amount.
 void expire()
          Set this Organism’s size and growth rate to zero.
 double getRate()
          Get the growth rate of this Organism.
 double getSize()
          Get the current size of this Organism.
 boolean isAlive()
          Determine whether this Organism is currently alive.
 void setRate(double newRate)
          Set the current growth rate of this Organism.
 void simulateWeek()
          Simulate the passage of one week in the life of this Organism.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Organism

public Organism(double initSize,
                double initRate)
Construct an Organism with a specified size and growth rate.

Parameters:
initSize - the initial size of this Organism, in ounces
initRate - the initial growth rate of this Organism, in ounces
Precondition:
initSize >= 0. Also, if initSize is zero, then initRate must also be zero.
Postcondition:
This Organism has been initialized. The value returned from getSize() is now initSize, and the value returned from getRate() is now initRate.
Throws:
java.lang.IllegalArgumentException - Indicates that initSize or initRate violates the precondition.
Method Detail

alterSize

public void alterSize(double amount)
Change the current size of this Organism by a given amount.

Parameters:
amount - the amount to increase or decrease the size of this Organism (in ounces)
Postcondition:
The given amount (in ounces) has been added to the size of this Organism. If this new size is less than or equal to zero, then expire is also activated.

expire

public void expire()
Set this Organism’s size and growth rate to zero.

Parameters:
- - none
Postcondition:
The size and growth rate of this Organism have been set to zero.

getRate

public double getRate()
Get the growth rate of this Organism.

Parameters:
- - none
Returns:
the growth rate of this Organism (in ounces per week)

getSize

public double getSize()
Get the current size of this Organism.

Parameters:
- - none
Returns:
the current size of this Organism (in ounces)

isAlive

public boolean isAlive()
Determine whether this Organism is currently alive.

Parameters:
- - none
Returns:
If this Organism’s current current size is greater than zero, then the return value is true; otherwise the return value is false.

setRate

public void setRate(double newRate)
Set the current growth rate of this Organism.

Parameters:
newRate - the new growth rate for this Organism (in ounces per week)
Precondition:
If the size is currently zero, then newRate must also be zero.
Postcondition:
The growth rate for this Organism has been set to newRate.
Throws:
java.lang.IllegalArgumentException - Indicates that the size is currently zero, but the newRate is nonzero.

simulateWeek

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

Parameters:
- - none
Postcondition:
The size of this Organism 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.