Created
December 6, 2012 02:46
-
-
Save kevinbarbour/4221427 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Rat { | |
private int num, den; | |
Rat() { | |
num = 1; | |
den = 1; | |
} | |
Rat(int num, int den) { | |
this.num = num; | |
this.den = den; | |
} | |
public void setNum(int num) { | |
if(num != 0) this.num = num; | |
} | |
public void setDen(int den) { | |
if(den != 0) this.den = den; | |
} | |
public int getNum() { return num; } | |
public int getDen() { return den; } | |
public Rat add(Rat rat) { return new Rat(num + rat.getNum(), den + rat.getDen()); } | |
public boolean isEqual(Rat rat) { | |
if(num == rat.getNum() && den == rat.getDen()) return true; | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment