Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Fraction {
- private final int num;
- private final int denom;
- public Fraction(int num, int denom) {
- this.num = num;
- this.denom = denom;
- }
- public int getNum() {
- return num;
- }
- public int getDenom() {
- return denom;
- }
- public Fraction add(Fraction other) {
- // Ignore cases where denom is 0 or other.denom is 0 or other is null. Also assume the denom are the same for both fractions
- return new Fraction(num + other.num, denom)
- }
- public Fraction subtract(Fraction other) {
- // Ignore cases where denom is 0 or other.denom is 0 or other is null. Also assume the denom are the same for both fractions
- return new Fraction(num - other.num, denom)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement