Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Fraction implements Comparable<Fraction>
- {
- private int num = 0, denom = 0;
- public Fraction(int num, int denom)
- {
- this.num = num;
- this.denom = denom;
- }
- public int compareTo(Fraction other)
- {
- double x = ((other.denom * num) - (other.num * denom));
- return (int)Math.signum(x);
- }
- public boolean equals(Object other)
- {
- if(other instanceof Fraction && compareTo((Fraction)other) == 0 )
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement