public class Plant extends Organism
Plant is an Organism with extra methods that
allow it to be eaten.
Java Source Code for this class:
http://www.cs.colorado.edu/~main/edu/colorado/simulations/Plant.java
Organism| Constructor and Description |
|---|
Plant(double initSize,
double initRate)
Construct a
Plant with a specified size and growth rate. |
| Modifier and Type | Method and Description |
|---|---|
void |
nibbledOn(double amount)
Have this
Plant lose some of its size by being eaten. |
public Plant(double initSize,
double initRate)
Plant with a specified size and growth rate.initSize - the initial size of this Plant, in ouncesinitRate - the initial growth rate of this Plant, in ounces
Precondition:
initSize >= 0. Also, if initSize is zero, then
initRate must also be zero.
Postcondition:
This Plant has been initialized. The value returned from
getSize() is now initSize, and the value
returned from getRate() is now initRate.java.lang.IllegalArgumentException - Indicates that initSize or initRate violates
the precondition.public void nibbledOn(double amount)
Plant lose some of its size by being eaten.amount - The amount of this Plant that is eaten (in ounces).
Precondition:
0 <= amount <= getSize().
Postcondition:
The size of this Plant has been decreased by
amount. If this reduces the size to zero, then
expire is activated.