【发布时间】:2016-10-26 19:50:30
【问题描述】:
对于我的作业问题,它是一个带有签名public int applyNutrientCoefficient() 的方法,它计算Pool 中的哪个Guppies 死于营养不良,并返回死亡人数。
使用Iterator<Guppy> 迭代Pool 中的guppiesInPool。对于每个Guppy,使用Random 方法nextDouble() 生成一个介于0.0 和1.0 之间的不同随机数。如果这个随机生成
数量大于池的营养系数,杀死Guppy
通过在Guppy 中设置适当的布尔字段。请注意,这
方法不会从池中移除任何死的孔雀鱼,它只会杀死
他们。不要做任何其他事情。
我有两门课,一门是Guppy 一门是Pool
在我的孔雀鱼课上,我做了一个布尔值 -
private boolean isAlive{}
public boolean getIsAlive(){
return isAlive
}
在我的 Pool 课上......
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
我得到的错误信息是找不到符号 - 方法isAlive()
有人可以帮忙吗
【问题讨论】:
-
一团糟,这不是有效的 java 代码。您缺少分号和括号。