problem1. Create a class Rational to provide at least following methods and constructors:
Rational r1= new Rational (3,5);
Rational r2= new Rational (4,7);
// also sub,mult,divide methods
Other that four operations you should provide methods which you think are useful for user of your class.
problem2. prepare a JFrame or JApplet (file name: TestRational.java) which performs the subsequent tasks:
i) Describe two arrays of size 10. Each element in the array references to a rational object which you wrote.
Rational a, b;
a = new Rational;
b = new Rational;
ii) Initialize the arrays in problem a) by making random Rational numbers. Do this by generating two random numbers between 1 and 9 for each Rational and using the numbers as the numerator and denominator. Denominator must be greater than Numerator. You must generate random numbers with Math.random.
iii) Display the contents of both arrays on the screen using JTextArea.
iv) Add a Scrollbar to JTextArea for scrolling up or down.
v) For each public method in rational class, create a corresponding JButton object. When the user clicks on a button, the actionPerformed listener must execute the corresponding rational method for all the elements in the two arrays and store the results in a new array. You must then display the result array in the JTextArea using the setText method. For ex, if the user hits the add button you should loop through all the elements in arrays and execute:
c[i] = a[i].add(b[i]);
v) If the user hits the sort button, uses the JTextArea method appends to append the results of sorting.