Question
ASAP PLEASE!! Adapted from Programming Exercises 13.18 Use the FastRational class, 15 points): Download FastRational.java from Canvas. It is the same as the Rational.java code
ASAP PLEASE!!
Adapted from Programming Exercises 13.18 Use the FastRational class, 15 points):
Download FastRational.java from Canvas. It is the same as the Rational.java code from Chapter 13 except that it uses a faster way from Chapter 22 to compute GCDs. In a file called TestFastRationalSeries.java
Write a program that uses the FastRational class to compute the following summation:
1/2 + 2/3 + 3/4 + ... + 98/99 + 99/100
First display the result using its toString method, and then using its doubleValue method.
You will discover that the output is incorrect: Series sum = 1349247664274259951/1822963237492290880 Series sum = 0.7401398100217947
The actual sum should quite a bit larger. The culprit is integer overflow
Here is the FastRational.java source code
If A rational nunber class that uses Euclid's Algarithn to quickly conpute ff grantast common d1visors. public class Fastfiatianal cxtends Kumbor inp innants Conparable-Fastfiatianals L privale stativ final luny serialversiunuld = 747694559364732976 ; If Data fielda for numerater and denaninator private long nunerator =; private long denominator = 1 ; f * Construct a rational with default properties / pub1e Fastfationalo ( ) his(b, 1): 3 f+ Construct a rational with specified nuneratar and dencrinator * / public Fastfational(long nunerator, long denoninator\} \{ if (dencninatur =B ) throw nnu Ar1thmenteException("Ratianal nunanr uith dennninator zoro"); lony ged = ycd(nunerator, dencninatur); this. nunerator = ((denerinatar >5)?1:1) numerator / ged; chis. Uenoninator = Malla sbs (denoninator) f ged; \} f+ Find BCD of two nunbers / private static long god( 10ngne long d) return rastbed(n, e); usn Euclid"s algorithn ta compute a GCD. / private static long fastoed(long nr long n ) If Assunas m and n are non-negative \{ if ( m=r=8 ) return nrr if {n=8) return mr if = Math,abe(in); n= Math abs(n); while (true) \{ long r=m \% if (r==8) rnturn n; it = ri; n=r \} 3 f+ Return nuterator / public lang getNumerator[J & return nuterator; l+ Return denoninator * public lang getbenowinator[\} \{ return denoninator; 3 f+ Add a rational nunber to this rational /
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