I am new to programming, and I have come into a problem when trying to equate two instances of a custom class.
Here is a simple class I have created to easily work with fractional numbers in java:
public class Fraction {
int numerator;
int denominator;
Fraction(int n, int d) {
numerator = n;
denominator = d;
}
public String toString() {
return numerator + "/" + denominator;
}
public double toDouble() {
return (double) numerator / denominator;
}
}
When I attempt to determine whether two Fractions are equal, it always returns false, even in cases like:
new Fraction(1,1) == new Fraction(1,1) //returns false
How can I make instances of my class equatable?