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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started