Advertisement
Guest User

Untitled

a guest
Jul 27th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.48 KB | None | 0 0
  1.     //Add method
  2.     public Rational add(Rational passedIn)
  3.     {
  4.         int addedNum, newDen, multiplier;
  5.         Rational addedRat = null;
  6.        
  7.         if(this.den == passedIn.den)
  8.         {
  9.             addedNum = this.num + passedIn.num;
  10.             newDen = this.den;
  11.         }//end for
  12.         else
  13.         {
  14.             newDen = this.den * passedIn.den;  
  15.             addedNum = (this.num * passedIn.den) + (this.den * passedIn.num);
  16.         }//end else
  17.        
  18.        
  19.         addedRat = new Rational(addedNum, newDen);
  20.        
  21.         reduce();
  22.        
  23.         return addedRat;   
  24.     }//end add
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement