Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please write a constructor and method inside class Polynomial. public Polynomial(int[] coefficients) The constructor that receives as argument the array of coefficients that define the

image text in transcribed

Please write a constructor and method inside class Polynomial.

public Polynomial(int[] coefficients) The constructor that receives as argument the array of coefficients that define the polynomial. For a polynomial of degree n, the array coefficients contains exactly n + 1 elements so that the coefficient of the term of order k is in the element coefficients[k]. For example, the polynomial 5x - 7x + 42 that will be used as an example in all of the following methods would be represented as the coefficient array {42, -7, 0, 5). Terms missing from inside the polynomial are represented by having a zero coefficient in that position. However, the coefficient of the highest term of every polynomial should always be nonzero, unless the polynomial itself is identically zero. If this constructor is given as argument a coefficient array whose highest terms are zeroes, it should simply ignore those zero coefficients. For example, if given the coefficient array {-1, 2, 0, 0, 0}, the resulting polynomial would have the degree of only one, as if that coefficient array had been {-1, 2} without those pesky higher order zeros. To guarantee that the Polynomial class is immutable so that no outside code can ever change the internal state of an object after its construction (well, at least not without resorting to underhanded Java tricks such as reflection), the constructor should not assign only the reference to the coefficients array to the private field of coefficients, but it absolutely positively must create a separate but identical defensive copy of the argument array, and store that defensive copy instead. This technique ensures that the stored coefficients of the polynomial do not change if some outsider later changes the contents of the shared coefficients array that was passed as the constructor argument. public int getDegree() Returns the degree of this polynomial, that is, the exponent of its highest order term that has a nonzero coefficient. For example, the previous polynomial has degree 3. Constant polynomials have a degree of zero

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advances In Databases And Information Systems 22nd European Conference Adbis 2018 Budapest Hungary September 2 5 2018 Proceedings Lncs 11019

Authors: Andras Benczur ,Bernhard Thalheim ,Tomas Horvath

1st Edition

3319983970, 978-3319983974

More Books

Students also viewed these Databases questions

Question

1. Discuss the four components of language.

Answered: 1 week ago

Question

f. What stereotypes were reinforced in the commercials?

Answered: 1 week ago