Java での OOP 導入プロジェクトの一環として与えられた課題を理解するのに苦労しています。すべての名前は変更されており、正確に翻訳されているわけではありません。次の方法を完了するよう求められます。
public boolean insertHorse(Horse horse) {
return true;
}
メソッドのシグネチャは変更できません。メソッドが含まれるクラスの馬の配列に馬を追加し、挿入が成功した場合は true を返し、そうでない場合は false を返すことになっています。だからこれは私がやったことです:
    public boolean insertHorse(Horse horse) {
    //Create a temp array with length equal to h
    Horse[] temp = new Horse[this.horses.length+1];
    //copy the horses to the temp array
    for (int i = 0; i < horses.length; i++){
        temp[i] = horses[i];
    }
    //add the horse on the temp array
    temp[temp.length-1] = horse;
    //change the reference of the old array to the temp one
    veiculos = temp;
    return true;
私の問題は、これがどのように、そしてなぜfalseになるのでしょうか? 農場の馬の数には制限がありますが、メソッドを呼び出す前にそれを確認することができます (そして計画していました)。これは私の悪い習慣ですか?
敬具、 ジョアン・シルバ