A polynomial is made of several terms, each term having a coefficient and a variable raised to a power. Polynomials are one-variable if all their terms contain only one variable. An example of such a polynomial is f(x) = 3x4 - 5x3 + 2x - 4. This polynomial has four terms.
The degree of a polynomial is defined as the highest power of the variable in a term. In the above example, the degree of the polynomial is 4. The polynomials we deal with have only positive, integral powers. The coefficients of our polynomials are also integral numbers.
Two polynomials are the same if they contain the same terms.
Several algebraic operations are possible with polynomials. The simplest one is evaluating the polynomial for a specific value of the variable. For example, for a polynomial
f(x)=3x4 - 5x3 + 2x - 4, its value at x = 2.5 is defined as
f(2.5) = 3 * (2.5)4 - 5 * (2.5)3 + 2 + (2.5) - 4 which is 40.0625.
Polynomials can be added together to create a new polynomial. The addition is performed by combining all the terms and adding the coefficients of the terms with the same power. For example 3x4 - 5x3 + 2x -4 + 2x3 + 2x2 + 4 = 3x4 - 3x3 + 2x2 + 2x. The degree of the sum is the maximum of the degrees of the two polynomials.
Download Polynomial.java Package: polynomial Start by the provided Polynomial interface and implement it in a class called PolynomialImpl. Beyond implementing the Polynomial interface, your implementation should have the following features/obey these constraints:
Polynomial.java starter code
package polynomial;
/**
* This interface represents all the operations offered by a polynomial. A
* polynomial is defined here as a function of one variable. The polynomial is a
* weighted sum of terms (the weights are numeric). Each term may either be an
* integer power of that variable, or some function in that variable, but never
* both (i.e. (log x)^2 is not allowed).
*/
public interface Polynomial {
/**
* Add this polynomial to another and return the result as another polynomial.
*
* @param other the other polynomial to be added
* @return the resulting polynomial
* @throws IllegalArgumentException if parameter is not the same concrete type
* as the current object.
*/
Polynomial add(Polynomial other) throws IllegalArgumentException;
/**
* Add a term to this polynomial with the specified coefficient and power.
*
* @param coefficient the coefficient of the term to be added
* @param power the power of the term to be added
* @throws IllegalArgumentException if the power is negative
*/
void addTerm(int coefficient, int power) throws IllegalArgumentException;
/**
* Determines if this polynomial is the same as the parameter polynomial.
*
* @param poly the polynomial to use
* @return true if this polynomial is of the same concrete type and has the same
* terms as the parameter, false otherwise
*/
boolean isSame(Polynomial poly);
/**
* Evaluate the value of this polynomial at the given value of the variable.
*
* @param x the value at which the polynomial is to be evaluated.
* @return the value of the polynomial at x
*/
double evaluate(double x);
/**
* Return the coefficient of the term with the given power.
*
* @param power the power whose coefficient is sought
* @return the coefficient at the given power
*/
int getCoefficient(int power);
/**
* Get the degree of this polynomial.
*
* @return the degree of this polynomial as a whole number
*/
int getDegree();
}