public class Organism
extends java.lang.Object
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
Constructor and Description |
---|
Organism(double initSize,
double initRate)
Construct an
Organism with a specified size and growth rate. |
Modifier and Type | Method and Description |
---|---|
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 . |
public Organism(double initSize, double initRate)
Organism
with a specified size and growth rate.initSize
- the initial size of this Organism
, in ouncesinitRate
- 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
.java.lang.IllegalArgumentException
- Indicates that initSize
or initRate
violates
the precondition.public void alterSize(double amount)
Organism
by a given amount.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.public void expire()
Organism
’s size and growth rate to zero.
Postcondition:
The size and growth rate of this Organism
have been set
to zero.public double getRate()
Organism
.Organism
(in ounces per week)public double getSize()
Organism
.Organism
(in ounces)public boolean isAlive()
Organism
is currently alive.Organism
’s current current size is greater than
zero, then the return value is true
; otherwise the return
value is false
.public void setRate(double newRate)
Organism
.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
.java.lang.IllegalArgumentException
- Indicates that the size is currently zero, but the newRate
is nonzero.public void simulateWeek()
Organism
.
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.