public class Polynomial extends Object
Polynomial
class represents a polynomial with integer
coefficients.
Polynomials are immutable: their values cannot be changed after they
are created.
It includes methods for addition, subtraction, multiplication, composition,
differentiation, and evaluation.
For additional documentation, see Section 9.9 of Algorithms, 4th Edition by Robert Sedgewick and Kevin Wayne.
Constructor and Description 

Polynomial(int a,
int b)
Initializes a new polynomial a x^b

Modifier and Type  Method and Description 

int 
compareTo(Polynomial that)
Compares two polynomials by degree, breaking ties by coefficient of leading term.

Polynomial 
compose(Polynomial that)
Returns the composition of this polynomial and the specified
polynomial.

int 
degree()
Returns the degree of this polynomial.

Polynomial 
differentiate()
Returns the result of differentiating this polynomial.

boolean 
equals(Object other)
Compares this polynomial to the specified polynomial.

int 
evaluate(int x)
Returns the result of evaluating this polynomial at the point x.

static void 
main(String[] args)
Unit tests the polynomial data type.

Polynomial 
minus(Polynomial that)
Returns the result of subtracting the specified polynomial
from this polynomial.

Polynomial 
plus(Polynomial that)
Returns the sum of this polynomial and the specified polynomial.

Polynomial 
times(Polynomial that)
Returns the product of this polynomial and the specified polynomial.

String 
toString()
Return a string representation of this polynomial.

public Polynomial(int a, int b)
a
 the leading coefficientb
 the exponentIllegalArgumentException
 if b
is negativepublic int degree()
public Polynomial plus(Polynomial that)
that
 the other polynomial(this(x) + that(x))
public Polynomial minus(Polynomial that)
that
 the other polynomial(this(x)  that(x))
public Polynomial times(Polynomial that)
that
 the other polynomial(this(x) * that(x))
public Polynomial compose(Polynomial that)
that
 the other polynomial(this(that(x)))
public boolean equals(Object other)
public Polynomial differentiate()
this'(x)
public int evaluate(int x)
x
 the point at which to evaluate the polynomial(this(x))
public int compareTo(Polynomial that)
that
 the other point0
if this polynomial is equal to the argument
polynomial (precisely when equals()
returns true
);
a negative integer if this polynomialt is less than the argument
polynomial; and a positive integer if this polynomial is greater than the
argument pointpublic String toString()
public static void main(String[] args)
args
 the commandline arguments (none)