CSC-1106 Homework 09 (Class and static methods) Due: Tuesday, November 22, 2016 Write a class encapsulating the concept of a rational number, a rational number has the following attributes: an integer representing the numerator of the number. number, and another integer representing the denominator of the rational The ratio should always be stored in its simplest form. For example, the rational number 40/12 should be stored as 103. The class has the following constructors and methods: A default constructor to set the Rational number to 0/1 A constructor that has parameters for the numerator and denominator, and converts the resulting ratio to simplified form simplify 0-a private method to convert the Rational number to simplified form getGCD (x, y) -a private static method to return the largest common factor of the two positive integers x and y (their greatest common divisor). For example, the greatest common divisor of 40 and 12 is 4. value 0-returns the Rational number as a double value o-returns the Rational number as a string in the form a/b toString multiply (Rational -a public method to return the Rational number after multiplied by Rational number r add (Rational r)-a public method to return the Rational number after addition with Rational number r floor (Rational r) -a public method to return the integer of the floor of the Rational number. max (Rational x, Rational )-a public static method to return the larger Rational number among x and y. Solution public class Rational { /** * A public constant that defines the rational value of 0. */ public static final Rational ZERO = new Rational(0, 1); /** * A public constant that defines the rational value of 1. */ public static final Rational ONE = new Rational(1, 1); /** * A public constant that defines the rational value of 0.5. */ public static final Rational HALF = new Rational(1, 2); /* * The Lowest and the Highest levels of precision allowed. */ private static final double LWST_PREC = 1E-3; private static final double HIST_PREC = 1E-16; private static double precision = 1E-10; private final long num; private final long den; private final double result; /** * Creates a new {@code Rational} with the given numerator and * denominator. It has special cases for Positive Infinity * ({@link java.lang.Double#POSITIVE_INFINITY Double.POSITIVE_INFINITY}), * Negative Infinity ({@link java.lang.Double#NEGATIVE_INFINITY * Double.NEGATIVE_INFINITY}) and Not A Number * ({@link java.lang.Double#NaN Double.NaN}. * * @param numerator The numerator. * @param denominator The denominator. */ public Rational(long numerator, long denominator) { // for dealing with \"infinities\" and \"NaN\": if (denominator == 0) { den = 0; if (numerator > 0) { num = 1; result = Double.POSITIVE_INFINITY; } else if (numerator < 0) { num = -1; result = Double.NEGATIVE_INFINITY; } else { num = 0; result = Double.NaN; } return; } if (denominator < 0) { numerator = 0L - numerator; denominator = 0L - denominator; } num = numerator;.