Create a class polynomial and a corresponding test class


Create a class Polynomial and a corresponding test class that is used to evaluate a polynomial function of x: P(x) = a0 + a1 * x + a2 * x ** 2 + ......+an * x ** n; ai is coefficient i, and x ** n means x to the power of n The coefficients ai, are of type double, and the exponents of x are integers. The largest exponent n is called the degree of the polynomial which is an integer >= zero. The class has the attributes: degree, the value of the largest exponent n. coefficients, an array of coefficients ai. And the following methods: Polynomial (max), which is a constructor that creates a polynomial of degree max with all "degree plus one" coefficients of zero. setConstast(i, value), sets the coefficient ai to value. evaluate(x), returns the value of polynomial for the given x. For example, p(x) = 3 + 5x + 2 * x** 3 is of degree 3, has coefficients a0 = 3, a1 = 5, a2 = 0,and a3 = 2. The invocation of evaluate(7) computes: 3 + 5 * 7 + 0 * 7 ** 2 + 2 * 7 **3 which returns 724.

Solution Preview :

Prepared by a verified Expert
Algebra: Create a class polynomial and a corresponding test class
Reference No:- TGS01230400

Now Priced at $10 (50% Discount)

Recommended (98%)

Rated (4.3/5)