CODE IN JAVA
(Rational Numbers) Create a class called Rational for performing arithmetic with fractions. Write a program to test your class. Use integer variables to re present the private instance variables of the class- the numerator and the denominator. Provide a constructor that enables an object of this class to be initialized when it's declared. The constructor should store the fraction in reduced form. The fraction 2/4 is equivalent t0% and would be stored in the object as l in the numerator and 2 in the denominator. Provide a no-argument constructor with default values in case no initiali zers are provided. Provide public methods that perform each of the following operations: a) Add two Rational numbers: The result of the addition should be stored in b) Subtract two Rational numbers: The result of the subtraction should be c) Multiply two Rational numbers: The result of the multiplication should d) Divide two Rational numbers: The result of the division should be stored e) Return a String representation of a Rational number in the form a/b, DReturn a String representation of a Rational number in a floating-point reduced form. stored in reduced form. be stored in reduced form. in reduced form. where a is the numerator and b is the denominator. format. (Consider providing formatting capabilities that enable the user of the class to specify the number of digits of precision to the right of the decimal point.) Java Rational_output run: Enter numerator 1: 1 Enter denominator 1: 3 Enter numerator 2: 7 Enter denominator 2: 8 Enter precision: 6 1. Add 2. Subtract 3. Multiply 4. Divide 5. Exit Choice: 1 a +b- 29/24-1.208333 1. Add 2. Subtract 3. Multiply 4. Divide 5. Exit a b--13/24 --0.541667 1. Add 2. Subtract 3. Multiply 4. Divide 5. Exit choipe: 3/24 - 0.291667 a *b- 1. Add 2. Subtract 3. Multiply 4. Divide 5. Exit Choice: 4 /-8/21 . 0.380952 Add 2. Subtract 3. Multiply .Divide 5. Exit Choice: BUILD SUCCESSFUL (total time: 1 minute 33 seconds) page 1