Question: Write program in Java Problem 1: (Rational) Write a class named Rational that represents a rational number Make Rational inherit java.1ang.Number httpa://docs.oracle.com/javase/9/doca/api/java/lang/Number.htal Make Rational mutable
Write program in Java


Problem 1: (Rational) Write a class named Rational that represents a rational number Make Rational inherit java.1ang.Number httpa://docs.oracle.com/javase/9/doca/api/java/lang/Number.htal Make Rational mutable Provide the following const ructons public Rational (nt nuserator, int denominator) public Rational (Biginteger nuserator, Biginteger denominator) where Biginteger is java.sath.Biginteger Override/implement all abatract methods inherited from java.1ang.Number equale and toString inberited from java.lang.Object, appropriate member functions named add, aubtract, sultiply, and divide, and e the getter methods getNuserator and getDenoninator Rational must be able to represent an ar bitrarily large numerator and denominator Two Rational objects must be the same if they represent the same number, regardless of how the denominator were provided. For example, Rational r1-nev Rational (1,2) Rational r2 nev Rational (-2,-4) Systes.out.println (r1) Systes.out println (r2): /7output should be the sane Systes.out printin (ri.equala (r2)): //output true You may want to use gcd of Biginteger for this Write the factory methods with signature public static Rational intToRational(int nu) public static Rational BigintegerToRational (BigInteger nu); which convert the input (a whole sumber) into a Rational that repreents the same number. Rational and its methods must work when the object represents0 You should handle division by O by throwing an exception. Don't worry about this since we haven't covered this topic yet
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
