Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

please help me with the tester part is very important. thanks Question 5. (Polynomial.java and PolynomialTester.java) Not all object classes represent tangible items. Write a

image text in transcribedimage text in transcribed

please help me with the tester part is very important. thanks

Question 5. (Polynomial.java and PolynomialTester.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 : F x = aut a x + a2x' + . . . +1 1x" i + a x" where coefficients a are floating point numbers, the exponents ofx are 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 ) and another that is a ID array of cocfficients 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+2r+5x2.Coefficients can be integers or doubles. Below is the UML diagram for this class: Pol ial -degree: int -coefficients: double Polynomial (deg int) +Polynomial (p : Polynomial) +setCoefficient (index int, value : double) : +getCoefficient (index int) double tevaluate(x double double tostring) t String tequals(obj2 Object) boolean are some extra hints to help you al Polynomial (deg int) thi 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 doublel :this method returns the computed value of the polynomial given the value of argument x. If we use our previous example polynomil 7+2+5x the value of this polynomial for a value of x-3 would be: 7+23)+5(3)+(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) tostring ): displays a polynomial to the console (see sample output on next pe 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 abstract and guneralized datu comes in through arguments and out through return statements See next page for tester class. Write an application class called PolynomialTester that accomplishes the following: Prompt the user to enter the degree of the desired polynomial Call your constructor and create the basic polynomial. At least make sure that the degree is positive and greater than zero .e, input validation). Prompt the user to enter all the necessary coefficients. Use a loop and your setCoefficient (method to set the coefficients for your polynomial. Display the "completed" polynomial. Prompt the user to enter in a value for x (double or int are both fine) Evaluate the polynomial for that value ofx and display the result. Use a sentinel loop to re-prompt the user to enter other values of x and to keep computing the evaluated polynomial until they enter the string "quit Before quitting, create a copy of the polynomial using your copy constructor. Show that they are equal using your equals) method and by printing them both out to the screen. Then allow the user to change one coefficient of their choice and show that they are different (use equals and display to the screen). This is not shown in the sample output below Write proper Java docs for your Polynomial.java source file and write normal comments for your tester. Enter palynomial degree: 4 Coeff for degree D 7 Coeff for degree 1: 2 Coeff for degree 2:5 Coeff for degree 3: 0 Coeff for degree 1 polynomial: 7.0 + {2.0)%^ 1 + {5.01x"2 + (1.0)x-4 Enter a v lue of x for which to evaluate the polynomial: 3 For x3, polynomial 139.0 Enter a value of x for which to evaluate the polynomial:-3.1 For x -3.1, polynomial141.2021 Enter a value of x for which to evaluate the polynomial: 9.26 For x9.26, polynomial7806.9089057599995 Enter a value of x for which to evaluate the polynomial: quit

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

Oracle 10g Database Administrator Implementation And Administration

Authors: Gavin Powell, Carol McCullough Dieter

2nd Edition

1418836656, 9781418836658

More Books

Students also viewed these Databases questions