|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectedu.colorado.simulations.Organism
edu.colorado.simulations.Animal
public class Animal
An Animal is an Organism with extra methods that
deal with eating.
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 |
|---|
public Animal(double initSize,
double initRate,
double initNeed)
Animal with a specified size, growth rate, and
weekly eating need.
initSize - the initial size of this Animal, in ouncesinitRate - the initial growth rate of this Animal, in ouncesinitNeed - the initial weekly eating requirement of this Animal, in
ounces per week
initSize >= 0 and initNeed >= 0.
Also, if initSize is zero, then
initRate must also be zero.
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.
java.lang.IllegalArgumentException - Indicates that initSize, initRate, or
initNeed violates the precondition.| Method Detail |
|---|
public void eat(double amount)
amount - the amount of food for this Animal to eat (in ounces)
amount >= 0.
Animal has eaten this week.
throw IllegalArgumentException
Indicates that amount is negative.public double getNeed()
Animal needs each
week.
Animal needs to survive
one week (measured in ounces)public void setNeed(double newNeed)
Animal.
newNeed - the new weekly food requirement for this Animal (in ounces)
newNeed >= 0.
Animal has been set to
newNeed.
java.lang.IllegalArgumentException - Indicates that newNeed is negative.public void simulateWeek()
Animal.
simulateWeek in class Organism- - none
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.public double stillNeed()
Animal still needs to
survive this week.
- - none
Animal still needs to survive
this week (which is the total need minus the amount eaten so far).
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||