but use an instance of ArrayList instead of an array. Make the following slight changes to the methods to reflectthat an ArrayList object can grow in size:
• Change the constructor’s parameter from the maximum degree to the desired degree.
• The method setConstant might need to add zero-valued coefficients before a
i . For example, if a0 = 3,a1= 5,a2 = 0,a3=2,a4= 0, and a5= 0,the polynomial would be of degree 3, since the last nonzero constantisa3.The invocation setConstant(8,15) would need to set a6 and a7 to 0 and a8 to 15.
Create a class Polynomial that is used to evaluate a polynomial function of x:
P(x) 5 a0+ a1x+1 a2x+x+ ...+ an-1 xn-1+ an xn
The coefficients ai are floating-point numbers, the exponents of x are integers, and the largest exponent n—called the degree of the polynomial—is greater than or equal to 0. The class has the attributes
• degree—the value of the largest exponent n
• coefficients—an array of the coefficients n
and the following methods:
• Polynomial(max)—a constructor that creates a polynomial of degree max whose coefficients are all 0
• setConstant(i, value)—sets the coefficient ai to value
• evaluate(x)—returns the value of the polynomial for the given value x
For example, the polynomial
P(x)= 3 + 5x + 2x3
is of degree 3 and has coefficients a0 5 3, a1 5 5, a2 5 0, and a3 5 2. The invocation evaluate(7) computes 3 + 5 × 7 + 0 × 7 + 2 × 73, which is3 + 35 + 0 + 686, and returns the result 724.
We need at least 10 more requests to produce the solution.
0 / 10 have requested this problem solution
The more requests, the faster the answer.