This is for a Fraction program. I have private ints num and den, Fraction, and FractionInterface – the standard homework problem. I have done pretty much everything and now have been stuck for a few hours on the equals method. Since other is an Object, I can’t equate it to Fraction. Here’s what I have:
public boolean equals(Object other){
if (other == this){
return true;
} else {
return false;
}
}
This compiles but it gives incorrect results:
1/2 eq 1/2 = true
1/2 eq 1/2 = true
1/2 eq 1/2 = false
1/2 eq 1/2 = false
If I try other == Fraction, it doesn’t compile. Thanks for any help!
Try this out:
First, cast the
otherobjectThen, determine the condition that the two fractions are equivalent.
This will include some logic involving the comparing of numerator and denominators (expect to use
getNum()andgetDen()for theotherFraction.