[Solved] SOLVED:Create a class Polynomial that is used to evaluate a polynomial

30 $

File Name: SOLVED:Create_a_class_Polynomial_that_is_used_to_evaluate_a_polynomial.zip
File Size: 659.4 KB

SKU: [Solved] SOLVED:Create a class Polynomial that is used to evaluate a polynomial Category: Tag:

Or Upload Your Assignment Here:


Create a class Polynomial that is used to evaluate a polynomial function of x:P(x) = a0 + a1x + a2x2 + … + an-1xn-1 + anxnThe 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 aiand the following methods:• Polynomial(n) – a constructor that creates a polynomial of degree n whose coefficients are all 0.• setCoefficient(i, value) – sets the coefficient ai to a value• evaluate(x) – returns the value of the polynomial for the given value xFor example, the polynomialP(x) = a0 + a1x + a2x2 + … + an-1xn-1 + anxnis of degree 3 and has coefficients of a0 = 3, a1 = 5, a2 = 0, a3 = 2. The invocation evaluate(7) computes 3 + 5 x 7 + 0 x 7 + 2 x 73, which is 3 + 35 + 0 + 686, and returns the result 724.To test your Polynomial class, create a driver class and paste the following code in the main method of your driver:Polynomial p = new Polynomial(3);p.setCoefficient(0, 3);p.setCoefficient(1, 5);p.setCoefficient(2, 0);p.setCoefficient(3, 2);System.out.println(p.evaluate(7));Using the above code in your driver class should produce 724 as output. Your Polynomial class must work with the above code.FIND ATTACHED FOR SOLUTION. SEE SCREENSHOT FOR SUCCESFUL PROGRAM OUTPUT =724

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[Solved] SOLVED:Create a class Polynomial that is used to evaluate a polynomial
30 $