-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 に答える