2つのレポートカードのマークを比較するコードを作成しようとしていますが、>または<のような演算子を使用するたびに、引数の型は未定義です。誰かが私が間違っていることを教えてもらえますか? (コメント)Java compareTo()未定義のオペレータ
編集:marks
の種類とgetMarks
はdouble[]
あります。
* @param other
* @return 1 if the average mark of calling object is more than average of parameter object
* -1 if the average mark of calling object is less than average of parameter object
* 0 if the average mark of calling object and the average of parameter object are the same
*/
public int compareTo(ReportCard other) {
if(this.marks > other.getMarks()) {
return 1;
} else if (this.marks < other.getMarks()) {
return -1;
} else {
return 0;
}
} //to be completed
あなたのコードは次のように単純化でき
「マーク」はどのようなタイプですか? –
marksはdouble型 – reez
です。また、getMarks()も 'double'を返しますか? – domsson