Skip to content

Latest commit

 

History

History
24 lines (18 loc) · 1.15 KB

README.md

File metadata and controls

24 lines (18 loc) · 1.15 KB

Developed class Polynomial as follows:

i. It has one field representing the coefficients of the polynomial using an array of double. A polynomial is assumed to have the form 𝑎0 + 𝑎1𝑥1 + ⋯ + 𝑎𝑛−1𝑥𝑛−1. For example, the polynomial 6 − 2𝑥 + 5𝑥3 would be represented using the array [6, -2, 0, 5]

ii. It has a no-argument constructor that sets the polynomial to zero (i.e. the corresponding array would be [0])

iii. It has a constructor that takes an array of double as an argument and sets the coefficients accordingly

iv. It has a method named add that takes one argument of type Polynomial and returns the polynomial resulting from adding the calling object and the argument

v. It has a method named evaluate that takes one argument of type double representing a value of x and evaluates the polynomial accordingly. For example, if the polynomial is 6 − 2𝑥 + 5𝑥3 and evaluate(-1) is invoked, the result should be 3.

vi. It has a method named hasRoot that takes one argument of type double and determines whether this value is a root of the polynomial or not. Note that a root is a value of x for which the polynomial evaluates to zero