For my assignment question it is a method with the signature public int applyNutrientCoefficient()
, that calculates which Guppies
in the Pool
have died of malnutrition, and returns the number of deaths.
Use an Iterator<Guppy>
to iterate over the guppiesInPool
in the Pool
. For each Guppy
generate a different random number between 0.0 and 1.0 inclusive using the Random
method nextDouble()
. If this randomly generated
number is greater than the Pool's nutrient coeffcient, kill that Guppy
by setting the appropriate boolean field in the Guppy
. Note that this
method does not remove any dead Guppies from the Pool, it just kills
them. Do not do anything else.
I have 2 classes one is Guppy
one is Pool
in my guppy class I made a boolean -
private boolean isAlive{}
public boolean getIsAlive(){
return isAlive
}
in my Pool class....
public int applyNutrientCoefficient()
int deathCount = 0
Iterator<Guppy> it = guppiesInPool.iterator()
while (it.hasNext() )
Guppy guppyOne = it.next()
if (randomNumberGenerator.nextDouble() > nutrientCoefficient)
if (guppyOne.isAlive() )
guppyOne.setAlive(false)
deathCount++
return deathCount
The error message I'm getting is cannot find symbol - method isAlive()
Can someone help please
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…