Question: Below are my codes, and I am having a problem with the class Rat. How can I fix this? Thank you --> int gcd =

Below are my codes, and I am having a problem with the class Rat. How can I fix this?

Thank you

--> int gcd = Euclidean.GCD(numerator, denumerator); this part

------------------------------------------------------------------------------------

public class Euclidean { protected static Ring euclidean(RM a, RM b) { if ((Comp.eq(a, b))||(Comp.eq(b,b.addIdentity()))) return a; else if(Comp.eq(a, a.addIdentity())) return b; else if(Comp.gt(a, b)) return euclidean((RM) a.mod(b),b); else return euclidean((RM) b.mod(a),a); } public static Ring GCD(RM a, RM b) { if(Comp.lt(a, a.addIdentity())) //if a < 0 a = (RM) a.addInverse(); if(Comp.lt(b, b.addIdentity())) //if b < 0 b = (RM) b.addInverse(); return euclidean(a, b); } public static Ring LCM(RM a, RM b) { Ring gcd = GCD(a, b); Ring q = b.quo(gcd); return a.mul(q); } } -------------------------------------------------------------------------------------------------

public class Rat implements Field, Modulo, Ordered { int n, d; public Rat(int numerator, int denumerator) { //TODO: make numerator and denominator prime to //each other using Euclidean.gcd int gcd = Euclidean.GCD(numerator, denumerator); this.n = numerator/(int)gcd; this.d = denumerator/(int)gcd; } //Modulo public Ring mod(Ring a) { Rat r = (Rat)a; if(r.n == 0) throw new ArithmeticException("Division by zero"); return new Rat((n*r.d) % (d*r.n), d*r.d); }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!