Question: Need help with the toString() method this is the code I have. public class Polynomial private int coefficients; the constructor creates a Polynomial with the
Need help with the toString() method this is the code I have.


public class Polynomial private int coefficients; the constructor creates a Polynomial with the specified coefficients (passed as the parameter c) It should set the coefficients instance variable to be an array which is a copy of c At the end, the constructor calls the "simplify" method, which makes sure that the first coefficient(s) of the polymonial are non-zero. public Polynomial(int[ c) coefficients new int length] complete this make sure that the first coefficient of the polynomial is not e simplify(); simplify should (if necessary) create a new array to be stored in the coefficients instance variable In the new array, the first coefficient will be nonzero. For example, int coeffs fe, e, 2, 1, Polynomial p new Polynomial (coeffs) p represents the function f(n) en 4 en 3 2n 2 n. We would like to get ride of the highest order term (s) with coefficient of 0. In this example after calling p. simplify() p's coefficients should be 12, 1, 01, which represents f(n) 2n 2 n public void simplify() int i; for (i e; i coefficients length && coefficients[ i++) fill in the code for this method System.out.println(coefficients); int[ newCoeff new int[coefficients.length i]; for (int j j newcoeff.length; j++){
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
