Answered step by step
Verified Expert Solution
Question
1 Approved Answer
26. You will create a class that represents a polynomial; for example, it could repre sent 5x3 2x -3 or x2- '1 a. Create a
26. You will create a class that represents a polynomial; for example, it could repre sent 5x3 2x -3 or x2- '1 a. Create a class called Pol ynom al Objects of this class represent a single polynomial. Attributes of such an object include its degree and the coeffi- cients of each of its terms. Provide a constructor that accepts the degree of the polynomial as an i nt parameter. Provide a transformer method called s et Coefficient that accepts as i nt parameters the degree of the term it is setting and the coefficient to which it should be set. For example, the polyno- mial 5x3 + 2x - 3 could be created by the sequence of statements: Pol ynoni al my Pol y = new Pol ynom al ( 3) ; ny Pol y. s et Coefficient (3, 5); myPol y. set Coeffi ci ent (1, 2); myPol y. s et Coeffi ci ent (0, - 3); Provide an evaluate method that accepts a float parameter and returns the value of the polynomial, as a fl oat, as evaluated at the parameter value. For example, given the previous code the following sequence of code would print -3.0, 4.0, and -1.375. Syst em out pri nt l n(ny Pol y. eval uat e(0): Syst em out . pri nt l n(ny Pol y. eval uat e (1)); Syst em out . pri nt ln(myPoly. eval uat e(0. 5)); Finally, provide a program, a "test driver," that demonstrates that your Pol y- nomi al class performs correctly
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