Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Question 2. (Polynomial java and Polynomial Tester.java Not all object classes represent tangible items. Write a class called Polynomial that represents and evaluates a polynomial

image text in transcribed

image text in transcribed

Question 2. (Polynomial java and Polynomial Tester.java Not all object classes represent "tangible" items. Write a class called Polynomial that represents and evaluates a polynomial expression. Recall that a polynomial function of x takes the form Px) a t ar +a,x2 +...+a, I +anx" where coefficients at are floating-point numbers, the exponents xe ofxare integers, and the largest exponent n-called the degree of the polynomial-is greater than or equal to zero. It sounds complicated but it might not be as bad as you think. Your class is defined by two data fields, one that represents the degree of the polynomial (the value of largest exponent n) and another that is a 1Darray of coefficients ai. Thus if the value of n is 4 and the coefficients in the array are (in order) 7,2, 5, 0, 1 the corresponding polynomial is 7+2x +5x +x". Coefficients can be integers or doubles. Below is the UML diagram for this class Polynomial degree int coefficients double +Polynomial (deg int) +Polynomial (p Polynomial) +setcoefficient (index int, value double) +getcoefficient (index int) double +evaluate (x double) double +toString String +equals (obj2 Object) boolean Here are some extra hints to help you along Polynomial(deg int) this is an argumented constructor that creates a new polynomial object with degree deg. The coefficients will all be 0 after the object is created. Polynomial(p: Polynomial) this is a copy constructor. It should take an existing polynomial object as an argument and should create a new one with the same degree and coefficients setCoefficient, getCoefficient should be straight forward (I think?!). Note: If the user enters invalid indices, do nothing (change no coefficient value, get no coefficient value) evaluate(x: double) this method returns the computed value of the polynomial given the value of argument x. If we use our previous example polynomial 7+2x +5x2 +x4, the value of this polynomial for a value of x would be: 7+2(30+503) +(3) 139. You'll need a loop to access all of the coefficients. equals(obj2): compares to Polynomials (or a polynomial and another object) for equality. Two polynomials are considered equal IFF they have the same degree and all the same coefficients (in the same order). toString0: displays a polynomial to the console (see sample output on next page) Use a loop to constructor your Write JavaDocs for the Polynomial class (not the tester) REMEMBER your tester class will do the input and output work; it will make use of your object. There should be No Scanners in the Polynomial class. Keep your methods abstractand generalized-data comes in through arguments and out through return statements

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

Database Systems Design Implementation And Management

Authors: Peter Rob, Carlos Coronel

3rd Edition

0760049041, 978-0760049044

More Books

Students also viewed these Databases questions

Question

Explain what a feasibility analysis is and why its important.

Answered: 1 week ago