Question: You will create a class that represents a polynomial; for example, it could represent 5 x 3 + 2 x 3 or x 2 1.
You will create a class that represents a polynomial; for example, it could represent\ 5\ x\ 3\ +\ 2\ x\ 3 or\ x\ 2\ 1.\ a.\ Create a class called\ Polynomial\ . Objects of this class represent a single poly-\ nomial. Attributes of such an object include its\ degree\ and the\ coefficients\ of each of its terms. Provide a constructor that accepts the degree of the poly-\ nomial as an\ int\ argument. Provide a transformer method called\ setCoeffi\ -\ cient\ that accepts as\ int\ arguments the degree of the term it is setting and the\ coeficient to which it should be set. For example, the polynomial 5\ x\ 3\ +\ 2\ x\ 3\ could be created by the sequence of statements:\ Polynomial myPoly = new Polynomial(3);\ myPoly.setCoefficient(3,5);\ myPoly.setCoefficient(1,2);\ myPoly.setCoefficient(0,3);\ Provide an\ evaluate\ method that accepts a\ double\ argument and returns the\ value of the polynomial, as a\ double\ , as evaluated at the argument value. For\ example, given the previous code the following sequence of code would print\ 3.0, 4.0, and 1.375.\ System.out.println(myPoly.evaluate(0.0));\ System.out.println(myPoly.evaluate(1.0));\ System.out.println(myPoly.evaluate(0.5));\ Finally, provide a program, a test driver, that demonstrates that your\ Polynomial\ class performs correctly.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
