Data Structure and Algorithms

profileSiper

  

A JAVA class Polynomial.java is provided. Your task is 

1. To complete the implementation of method public Polynomial addPolynomial (Polynomial p).

Requirements: 

The method implements addition of two polynomials in algebraic sense.

This method takes a polynomial as an input and returns a polynomial that is the sum of the current polynomial and the input polynomial

For example, assume the current polynomial is 10x20 - 9x7 + 3 and the input polynomial is 12x16 + 6x7 - 20x2 – 2, then the returned polynomial must be
10x20 - 3x7 -20x2 +1

2. To add code in main to test your implementation.

Hint:

With the assignment, a version of method addTerm is provided. But in its implementation, it does not handle the case where the new term to be added has the same degree as a term that already exists in the current Polynomial. You may need to modify the code in this method so that it will handle this situation. For example, if the polynomial currently has a term -10x^5 and the new term to be added is 4x^5, then after method addTerm(4, 5) is called, the polynomial should be -6x^5.

After that done, to implement addPolynomial, all you need to do is to add all the terms to a new Polynomial object

  • 9 years ago
  • 15
Answer(1)

Purchase the answer to view it

blurred-text
  • attachment
    Polynomial.zip