[Solved]Write Overloaded Version Add Takes Int Parameter Seen Classes Convert String Static Method Q37273575
-
Write an overloaded version of add that takes an int asparameter.
-
We have seen other classes convert a string with a static method( like Double.parseDouble). We could do the same thing in theRational class, starting from the heading
public static Rational parseRational(String s)
Note that you can take the basic logic from the Pythonconstructor.
Here’s the SortRational.java code that’s needed:
// Illustrating that the Comparable interface// allows sort to work.”’import java.util.Collections;import java.util.ArrayList;public class SortRational{ public static void printRationals(ArrayList<Rational> rList) { for (Rational r : rList) System.out.print(” ” + r); System.out.println(); } public static void main(String[] args) { ArrayList<Rational> rList = new ArrayList<Rational>(); Rational[] rArray = {new Rational(5, 3), new Rational(34, 14), new Rational(-7, 4), new Rational(4, 6)}; for (Rational r : rArray) rList.add(r); System.out.print(“Original list: “); printRationals(rList); Collections.sort(rList); System.out.print(“Sorted list: “); printRationals(rList); }}
Expert Answer
Answer to Write an overloaded version of add that takes an int as parameter. We have seen other classes convert a string with a s… . . .
OR

