import java.util.Scanner; public class TestChapter8 { public static void main(St
ID: 3530397 • Letter: I
Question
import java.util.Scanner; public class TestChapter8 { public static void main(String[]args) { Scanner input = new Scanner(System.in); Polynomial p1 = new Polynomial(3); p1.setCoefficient(0, 3.0); p1.setCoefficient(3, 5.0); //print results System.out.println("The solution to the polynomial is : " + p1.evaluate(3)); } } class Polynomial { private int degree; private double[] coefficients; //changed value to d public Polynomial(int d) {//Polynomial(int max): a constructor that creates a polynomial of degree max whose coefficients are all zero degree = d; coefficients = new double[degree+1]; d = (int)coefficients[0]; for (int i = 0; i < coefficients.length; i++) { if (d < coefficients.length) d = (int)coefficients[i]; } } public int getDegree() { return degree; } public double getCoefficient(int i) { return coefficients[i]; } public void setCoefficient(int i, double value) {//void setCoefficient(int i, double value): sets the coefficient to value (i is in the range 0 to degree, namely there are degree + 1 coefficients in total) value = coefficients[i]; } public double evaluate(double x) {//double evaluate(double x): returns the value of the polynomial for the given value x double result = coefficients[0]; // Compute polynomial value for(int i = 0; i < coefficients.length; i++){ result += coefficients[i] * Math.pow(x, degree); } return result; } }Explanation / Answer
what program is this?
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.