1. Write a class named Rational to represent Rational numbers. The UML represent
ID: 3634311 • Letter: 1
Question
1. Write a class named Rational to represent Rational numbers. The UML representation of the class is:Rational
__________________________________________
-numerator: long
-denominator: long
__________________________________________
+Rational()
+Rational(long numerator, long Denomination)
+getNumerator(): long
+getDenominator(): long
+setNumerator(num:long): void
+add(Rational secondRational): Rational
+multiply(Rational secondeRational): Rational
+subtract(Rational secondeRational): Rational
+divide(Rational secondeRational): Rational
+equals(r: Rational): Boolean
+compareTo(r: Rational): long
+toString(): String
-gcd(num: long, den:long) : long
• Default value for a Rational obect is 0/1
• Rational objects must be in reduced form
• Rational objects should not be modified by an of the methods
• toString() format is “numerator/denominator”
2. Given n, write a program that will compute the following summation series using the Rational class. Output should as follows:
1/1+1/2+1/3………..+1/n=result
3. Write a program to do the following:
a) Generate a list of ten random rational numbers(numerator and denominator should be in range of 1 to 100 inclusively)
b) Print the list
c) Find the maximum value in the list
d) Print the result.