Question
#Object-oriented programming II Problem 3 (Adapted from Programming Exercise 13.15 Use BigInteger for the FastRational class, 15 points): Create a new class called BigRational. Base
#Object-oriented programming II
Problem 3 (Adapted from Programming Exercise 13.15 Use BigInteger for the FastRational class, 15 points):
Create a new class called BigRational. Base it on the FastRational class but use java.math.BigInteger for both the numerator and denominator. (The BigInteger class was covered in Section 10.9.) This will require that you modify most or all of the methods from FastRational. For instance, when the operators +, -, *, or / where performed on the numerator or denominator, you will now need to use .add, .subtract, .multiply, or .divide, respectively. Note that the BigInteger class comes with a gcd method, so use that for computing gcds! BigRational must extend Number. In a file called TestBigRationalSeries.java write a test program that computes and displays the series as specified in Problem 2. It should work correctly this time:
Series sum = 264414864639329557497913717698145082779489/278881500918849908658
1352357412492142272
Series sum = 94.8126224823604
NOTE: For problem 3: replace the long with BigInteger as the below: private BigInteger numerator = new BigInteger("0"); private BigInteger denominator = new BigInteger("1"); and then you need to modify the four basic calculations: public BigRational add(BigRational secondRational) { BigInteger n = (numerator.multiply(secondRational.getDenominator())).add(denominator.multiply(seco ndRational.getNumerator())); BigInteger d = denominator.multiply(secondRational.getDenominator()); return new BigRational(n, d); } an example for the add method and the rest subtract, multiply, and subtract can be modified accordingly.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started