Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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 yetStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started