Question: JAVA Programming Implement a class, Polynomial, to represent single-variable polynomials and write a test program. The functionality of the Polynomial class is as follows: -

JAVA Programming

Implement a class, Polynomial, to represent single-variable polynomials and write a test program. The functionality of the Polynomial class is as follows:

- Provide at least three constructors: a zero-parameter constructor that makes the polynomial zero, a constructor that makes a separate independent copy of an existing polynomial, and a constructor that creates a polynomial based on a String specification. The last constructor can throw an exception if the String specification is invalid, and you can make a design decision on what a valid specification is.

- negate returns the negative of this polynomial.

- add, subtract, and multiply return a new polynomial that is the sum, difference, or product, respectively, of this polynomial and another polynomial, rhs. None of these methods change either of the original polynomials.

- equals and toString follow the standard contract for these functions. For toString make the String representation look as nice as you can.

- The polynomial is represented by two fields. One, degree, represents the degree of the polynomial. Thus x2+2x +1 is degree 2, 3x + 5 is degree 1, and 4 is degree 0. Zero is automatically degree 0. The second field, coeff, represents the coefficients (coeff[i] represents the coefficient of xi ).

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!