したがって、質問では次のことを行うように求められます。
public boolean addRating(int rating)
ビデオの評価を追加します。評価が 1 から 5 までの場合、このビデオの評価を更新し、受け取った評価の数を追跡して true を返します。それ以外の場合は、エラー メッセージを出力して false を返します。
そして、これは私がなんとかしたことです:
public class Video {
private int rating;
public boolean addRating(int rating){
this.rating = rating;
boolean result;
int newRating = rating;
if(newRating>=1 && newRating <=5){
rating = newRating;
result = true;
}
else{
System.out.println("ERROR!");
result = false;
}
return result;
}
私の質問は、ビデオが評価された回数を正確にカウントするにはどうすればよいですか?