Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create a class that represents a polynomial; for example, it could represent (5x^3)+(2x)-3 or (x^2)-1. a. Create a class called Polynomial. Objects of this class

Create a class that represents a polynomial; for example, it could represent (5x^3)+(2x)-3 or (x^2)-1.

a. Create a class called Polynomial. Objects of this class represent a single polynomial. Attributes of such an object include its degree and the coefficients of each of its terms. Provide a constructor that accepts the degree of the polynomail as an int parameter. Provide a transformer method called setCoefficient that accepts as int parameters the degree of the term it is setting and the coefficent the coefficient to which it should be set. For example, the polynomial (5x^3)+(2x)-3 or (x^2)-1 could be created by the sequence of statements:

Polynomial myPoly = new Polynomial(3);

myPoly.setCoefficient(3,5);

myPoly.setCoefficient(1,2);

myPoly.setCoefficient(0,-3);

Provide an evaluate method that accepts a float parameter and returns the value of the polynomial, as a loat, as evaluated at the parameter value. For example, given the previous code the following sequence of code would print -3.0, 4.0, and -1.375.

System.out.println(myPoly.evaluate(0));

System.out.println(myPoly.evaluate(1));

System.out.println(myPoly.evaluate(0.5));

Finally, provide a program a "test driver," that demonstrates that your Polynomial class performs correctly.

b. Create an application that accepts the degree of a polynomial and the coefficients of the polynomial, from highest degree to lowest, as a command line parameter and then createst the corresponding Polynomial object. For example, the polynomial (5x^3)+(2x)-3 or (x^2)-1would be represented by the command line parameter "3 5 0 2 -3." The program should then repeatedly prompt the user for a float value at which to evaluate the polynomial and report the result of the evaluation. A sample run, assuming the previously stated command line parameter, might look something like this?

Enter a value> 0

The result is -3.0

Continue?> Yes

Enter a value> 1

The result is 4.0

Continue?> Yes

Enter a value> 0.5

The result is -1.375

Continue?> No

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

Datacasting How To Stream Databases Over The Internet

Authors: Jessica Keyes

1st Edition

007034678X, 978-0070346789

More Books

Students also viewed these Databases questions