Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Develop a Java program that can be used to add polynomials. In general, a polynomial is an algebraic expression of the form: P(x) =
Develop a Java program that can be used to add polynomials. In general, a polynomial is an algebraic expression of the form: P(x) = aoxn-1 + axn-2 + axn-3 + ... + an-2x + an-1 E (1) = To + T + T, + ... + Tn-z + Tn-i Each term of the polynomial, T = axn-(i+1), has a coefficient a; and an exponent n - (i+1). The expression for P(x) doesn't have to include all terms, To, T,..., Tn-1 as some coefficients might be zero. Therefore, one needs to keep track of the non-zero coefficients. It is suggested that your program defines a class, say, polynomial, as well as methods to process objects of that class. The coefficients and exponents of terms (along with the number of non-zero terms) are to be maintained for polynomial object instance. Methods of the class should allow the user to carry out at least the following: Initialize a polynomial. A new polynomial starts with no terms. (Hence, the number of terms in it is zero.) Append a new term to a polynomial object. Each term is specified by a coefficient and an exponent for x. Appending a term to a polynomial increases the number of terms in it by 1. Input a polynomial. Such a method allows the user to enter the number of terms, and the coefficients and exponents of all terms. (The method to input a polynomial might make use of the method that appends a term to a polynomial.) Add two polynomials. Given two polynomials, it computes their sum. Display a polynomial. This allows the user to display the non-zero terms of a polynomial in the form given by (1). Submit a brief report that includes a listing of your program and results of several test runs. A run test prompts the user to enter two polynomials P, P2, computes their sum, P3 = P+ P, and displays all three polynomials, P, P2 and P3. Assume that the highest degree of a polynomial is a constant MAX_DEG (e.g., 10). You should insert sufficient comments in your code to make it self-explanatory. If necessary, include pseudo-code that explains the underlying algorithms used in developing the program. Reading such code might be read at the discretion of the grader.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Below is an example Java program that implements a polynomial class with the specified functionalities java import javautilScanner class Polynomial pr...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