-4

我做这种编码已经有一段时间了。所以我想知道是否有什么地方我必须进行更改以允许我制作一个合适的 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 */

}
4

1 回答 1

2

我不确定类resultOfLastInteraction()中的实现Dog(我假设它的名称与之相似),但它必须返回null.

此外,为了澄清起见,通过“返回a NullPointerException”,正确的术语是说抛出a NullPointerException

于 2013-09-07T00:16:28.903 回答