Question
Finish this code using bernoulli number equation in java: (Implify this function below) class Rational { long num; // The numerator long den; // The
Finish this code using bernoulli number equation in java: (Implify this function below)
class Rational { long num; // The numerator long den; // The denominator /* For negative rational numbers, only the numerator will be negative. For the methods add, sub, mult, div we provide two forms. In the first form we create a new rational number by having a given rational number add, subtract, multiply, or divide itself by another rational number and return the result as a new rational number. The calling rational number is unaltered. In the second form a given rational number adds, subtracts, multiplies or divides its value by a given constant value and returns the result as a new rational number. Once again, the calling rational number is unaltered. In both cases the computed rational values are reduced to lowest terms before being returned. */ public Rational(long x, long y) { num = x; den = y; } public Rational add(Rational a) { return reduce(new Rational(num * a.den + a.num * den, den * a.den)); }//add1 public Rational add(long a) { return reduce(new Rational(num + a * den, den)); }//add2 public Rational sub(Rational a) { return reduce(new Rational(num * a.den - a.num * den, den * a.den)); }//sub1 public Rational sub(long a) { return reduce(new Rational(num - a * den, den)); }// sub2 public Rational mult(Rational a) { return reduce(new Rational(num * a.num, den * a.den)); }//mult1 public Rational mult(long n) { return reduce(new Rational(num * n, den)); }//mult2 public Rational div(Rational a) { return reduce(new Rational(num * a.den, den * a.num)); }//div1 public Rational div(long n) { return reduce(new Rational(num, den * n)); }//div2 /* The following method is intended to place a rational number in reduced (or "lowest terms") form. It is implemented by factoring the gcd of the numerator and denominator from both. We use Euclid's method to find the gcd. */ public Rational reduce(Rational a) { long gcd; if (a.den
a.num /= gcd; a.den /= gcd; return a; }//reduce // Euclid's algorithm private long euclid(long a, long b) { if (b == 0) return a; else return euclid(b, a % b); }//euclid // will display a rational number in the form num / den public String toString() { if (num==0) return "0"; else if (num==den) return "1"; else return (num+"/"+den); }//toString }//Rational
Use this Template to complete this program:
Assignment specification Consider a sequence of values A(0),A(1),A(2), with the following properties: 1. A(0)=1. 2. A(1)=21. 3. A(N) is rational for all N, where N=0,1,2,3 4. A(N)=N+11K=0N1(N+1K)A(K). for N=2,3, etc
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