我做了这种编码已经有一段时间了。所以我想知道是否有某个地方我必须做出改变才能让我做一个合适的java测试人员。
public void performMove(Dog otherDog, float randomNumber) {
/* Parameters for attack vs. Attack */
if(!(this.isDefending)&&!(otherDog.isDefending)){
if((randomNumber * 100) >= speed){
otherDog.getHit((int)Math.round(0.25*power));
}
else{
resultOfLastInteraction = "...." + this.name + "miss";
}
}
/*Parameters for Attack vs. Defend*/
else if(!(this.isDefending) && (otherDog.isDefending)){
if((randomNumber * 100 >= 0) && (randomNumber * 100 <= 50)){
otherDog.getHit((int)Math.round(0.25*power));
}
else if((randomNumber * 100 >= 51) && (randomNumber * 100 <= 75)){
this.getHit((int)Math.round(0.25*power));
}
else if((randomNumber * 100 >= 76) && (randomNumber * 100 <= 100)){
this.getHit((int)Math.round(0.25*power));
}
/*Parameters for Defend vs. Defend */
else if((this.isDefending) && (otherDog.isDefending)){
resultOfLastInteraction = "Stale Mate";
}
else{
resultOfLastInteraction = "Select Move";
}
}
/* stubbed */
}
答案 0 :(得分:2)
我不确定resultOfLastInteraction()
类中Dog
的实现(我假设它的名称与此类似),但它必须返回null
。
此外,只是为了澄清,“返回一个NullPointerException
”,正确的术语是投掷一个NullPointerException
。