Question
*JAVA* Exercise1) You will create a class that represents a polynomial; for example, it could represent 5x^3 + 2x 3 or x^2 1. a. Create
*JAVA* Exercise1) You will 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 polynomial as an int argument. Provide a transformer method called setCoefficient that accepts as int arguments the degree of the term it is setting and the Exercises 58 Chapter 1 Getting Organized coefficient to which it should be set. For example, the polynomial 5x^3 + 2x 3 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 double argument and returns the value of the polynomial, as a double, as evaluated at the argument value.
System.out.println(myPoly.evaluate(0.0));
System.out.println(myPoly.evaluate(1.0));
System.out.println(myPoly.evaluate(0.5));
For example, given the previous code the following sequence of result would be
3.0,
4.0,
1.375.
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 argument and then creates the corresponding Polynomial object. For example, the polynomial 5x^3 + 2x 3 would be represented by the command line argument 3 5 0 2 3. The program should then repeatedly prompt the user for a double value at which to evaluate the polynomial and report the result of the evaluation. A sample run, assuming the previously stated command line argument, might look something like this:
Enter a value> 0.0
The result is 3.0
Continue?> Yes
Enter a value> 1.0
The result is 4.0
Continue?> Yes
Enter a value> 0.5
The result is 1.375
Continue?> No
c. Create an application that accepts the degree of a polynomial and the coefficients of the polynomial as a command line argument as in part b. The program should then prompt the user for two double values that will represent the end points of an interval on which the polynomial is defined. Your program should then calculate and output the approximation of the definite integral of the polynomial on the indicated interval, using 1,000 bounding rectangles.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started