Assignment Five
A polynomial (for the purpose of this assignment) is a sequence of terms where a term is an integer coefficient and a non-negative exponent. For example
3x2 + 4x4 + x6
2 + 5x2 + 6x3 + 2x7
4x10
The terms of polynomial 1 are (3,2), (4,4) and (1,6). The terms of polynomial 2 are (2,0), (5,2), (6,3) and (2,7). Polynomial 3 has only one term (4,10). You are to write a class Polynomial with the following specifications:
A private inner class Term with 2 int fields and one constructor that has 2 ints (a coefficient and an exponent) as parameters.
A private inner class Node with 2 fields, a Term field and a Node field and a constructor with Term and Node parameters.
A private Node field which will be used to represent a polynomial as a singly linked list with a list head. The exponents will be in order from the smallest to the largest like in the examples above.
A public constructor that constructs the null polynomial (the polynomial with 0 terms).
A private constructor that constructs a polynomial from a Node parameter.
A (recursive or non-recursive) public method void addTerm(int coefficient, int exponent) which places the Term in it's sorted (by exponent low to high) position in the singly linked list.
A recursive public method Polynomial polyAdd(Polynomial p) that adds this to p
A recursive public method Polynomial polyMultiply(Polynomial p) that multiplies this by p
An overridden toString method that return a String representation of a polynomial as a sum of coefficient*x^exponent terms. For example polynomial 1 above would have the following String representation
3*x^2 + 48*x^4 + x^6
Use the main class Polynomials to test your class. This assignment is due on March 29th at class time. Send me an e-mail with the Polynomial.java file attached and hand in a listing of Polynomial.java.