-2
基本的には、古い配列(PredatorList)より1つ大きい要素(newList)を作成する必要があります。私が下のコードから編集するつもりなのは、increaseArrayメソッド内のものだけです。メソッド名/シグネチャを編集することはできません。私はそれにJunitテストを実行する必要がありますが、私はエラーを取得し続け、私は理由を知らない。これまでの私のコード:アレイの長さを増やすのに役立つ人はいますか?
public class Pack {
/**
* Predator list. This contains the list of all Predators.
* The list should never contain a null in the middle and should never have more than one
* blank at the end (eg a null).
*/
private Predator[] PredatorList = new Predator[0];
/**
* Increase the array by one. You will need to create a new array one element
* bigger than the old array.
* No External Classes Permitted to Be Used in This Method
* My Solution Length in Lines (note yours can be longer or shorter): 3
*
*/
private void increaseArray() {
int increment = 1;
Predator[] newList = new Predator[PredatorList.length + increment];
for (int i = 0; i < PredatorList.length; i++) {
newList[i] = PredatorList[i];
}
}
}
私はこれを示していますが、私は実際にそれを読むのか分からないPackTestクラスを持っています。
public void testAddPredator2()
{
Pack list = null;
//add normal Predator
list = buildTestSet();
//System.out.println("->"+list.getNumberOfPredators());
int before = list.getNumberOfPredators();
list.addPredator(new Predator("Pony",100,100,5));
int after = list.getNumberOfPredators();
//System.out.println("->"+list.getNumberOfPredators());
assertEquals(before+1,after);
countOfSuccesfulTests++;
}
助けがあれば助かります。乾杯!
どのようなエラーが表示されますか? increaseArrayの最後に 'PredatorList = newList;'を追加して、新しい変数をインスタンス変数に代入する必要があるのが分かります。 – iNan
あなたは知っている、私は、私は "私はエラーが出てくる"と言うSOの投稿を見るたびに、私は "私はあなたに答えを与えている"と応答するつもりだと思う。ポスターがエラーの内容を教えてくれない場合は、その答えを教えてもらう必要はありません。 :) – ajb
問題は、私はJunitの仕組みを理解できないため、エラーが何であるか分かりません。表示するPackTestクラスがあります(上記の元の質問に入れました) – BobSacamano