Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

5 Polynomials (30 points) Write a class Poly java to represent polynomials (ie, functions of the form a+ba+ dz + e). Implement the following methods:

image text in transcribed
5 Polynomials (30 points) Write a class Poly java to represent polynomials (ie, functions of the form a"+ba+ dz + e). Implement the following methods: r2 + Poly(int) coefficients): Constructor for an array of coefficients where cln] is the cocfficient of In other words, the polynomial 23r-82 4 would be represented by the array 4, 0, -8,0,3,2. This way, if I want to know the cocfficient of 2, I look at c/2], and get 8. This convenience is worth the confusion that arises because we usually write arrays left- to-right starting from the smallest index, whereas we usually write polynomials left-to-right starting from the largest coefficient. int degree): Return the power of the highest non-zero term String toString): Overriding the Object class's toString method, this should return a String representation of the polynomial using r as the variable, arranged in decreasing order of exponent and printing nothing for terms with a coefficient of zero. For example, the Poly represented by the array [4,0, -8,0, 3,2] should return the string: 2x 5+3x 4-8x 2+4 Poly add(Poly a): To add two polynomials, simply add together cach scale degree in turn. Thus, (DP + 3r4-822 + 4) t (z? + 4z? _ 2r)-(DP + 3r423-4 r2-2x t 4). Create a method that constructs and returns a new Poly object with a new coefficient array created by adding the coefficients of the current object and the Poly object a passed as an argument to the add() function. e double evaluate(double x): Return the value of the function at the point r. In other words, if the Poly object represents 2r 3r 8r 4 and evaluate(2.0) is called, the method should calculate 2(2)5 + 3(2)4-8(2)2 + 4 and return 84. Within the main) method of the Poly class, create a series of tests which exercise cach of these methods and report their success or failure

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 Spatial And Temporal Databases 10th International Symposium Sstd 2007 Boston Ma Usa July 2007 Proceedings Lncs 4605

Authors: Dimitris Papadias ,Donghui Zhang ,George Kollios

2007th Edition

3540735399, 978-3540735397

More Books

Students also viewed these Databases questions