Advertisement
Guest User

Untitled

a guest
Jul 6th, 2015
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. public class Fraction {
  2. private final int num;
  3. private final int denom;
  4.  
  5. public Fraction(int num, int denom) {
  6. this.num = num;
  7. this.denom = denom;
  8. }
  9.  
  10. public int getNum() {
  11. return num;
  12. }
  13.  
  14. public int getDenom() {
  15. return denom;
  16. }
  17.  
  18. public Fraction add(Fraction other) {
  19. // 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
  20. return new Fraction(num + other.num, denom)
  21. }
  22.  
  23. public Fraction subtract(Fraction other) {
  24. // 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
  25. return new Fraction(num - other.num, denom)
  26. }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement