Exemple #1
0
  private Fraction1 reduce() {
    Fraction1 result = new Fraction1();

    int common = 0;
    int numer = Math.abs(num);
    int denomin = Math.abs(denom);

    if (numer > denomin) common = gcd(numer, denomin);
    else if (num < denomin) common = gcd(denomin, numer);
    else common = numer;

    result.num = num / common;
    result.denom = denom / common;
    return result;
  }
Exemple #2
0
 public Fraction1 multiply(Fraction1 fra) {
   int newNum = num * fra.num;
   int newDenom = denom * fra.denom;
   Fraction1 frac = new Fraction1(newNum, newDenom);
   return frac.reduce();
 }
Exemple #3
0
 public Fraction1 add(Fraction1 fra) {
   int newNum = ((fra.num * denom) + (num * fra.denom));
   int newDenom = denom * fra.denom;
   Fraction1 frac = new Fraction1(newNum, newDenom);
   return frac.reduce();
 }