比較餾分,使林和我平等類與布爾
public boolean equals(Object other) {
if (other.equals(this.numerator) && other.equals(this.denominator))
return true;
else
return false;
}
出現問題,將會給我的EQ 9/2 9/2 =假的結果。
(我對裁判的代碼休息) https://gist.github.com/anonymous/6604f427cc9d17391478
我到底做錯了什麼?
我編輯的代碼,但仍和處理布爾的錯誤和int
public boolean equals(Object other) {
if (other.equals(this.numerator) == getNumerator() && other.equals(this.denominator)== getDenominator())
return true;
else
return false;
}
你應該用'Java'標籤標記你的問題 – Ofiris
對不起! – user3369798
您的邏輯不正確,因爲您應該使用此對象的分子檢查另一個對象的分子,並使用此對象的分母檢查另一個對象的分母。目前,你正在用分母和這個對象的分子來檢查另一個對象的相等性,它總是會給你錯誤的。 –