I have this program to write, my instructor is terrible, and I have no idea how
ID: 3530239 • Letter: I
Question
I have this program to write, my instructor is terrible, and I have no idea how to start it. create a class polynomial used to evaluate a polynomial function of x: the coefficients are floating numbers, the exponents of x are integers, and the largest exponent n called the degree of the polynomial is greater than or equal to 0. the class has attributes degree - the value of the largest exponent n coefficients - an array of the coefficients and the following methods polynomial(max) - a constructor that creates a polynomial of degree mas whos coefficients are all 0 setConstant(I, value) - sets the coefficient a to value evaluate(x) - returns the value of the polynomial for the given value x. where do I start?Explanation / Answer
u must defin the class public to give access to other classes as well as that is the basic class of the function public class Polynomial { private int degree; //define as private nobody else can use private double[] coefficients; private double k; public Polynomial(int max) { //Polynomial(int max): a constructor that creates a polynomial of degree max whose coefficients are all zero degree = max; coefficients = new double[degree]; max = (int)coefficients[0]; for (int i=0;i=0;i--) { do { p = k * (Math.pow(x,exponent)); exponent--; sum+=p; result=sum; } while(exponent>=0); } return result; } } this will make a class use this class in main create a polynomail type object and call polynomial A; A.polynomial() will create this object then apply te required methods on it to gt the desired result u may provide a destructor also in the definition of class ... otherwise the compiler will itself provide the destructor to destrooy the object created in main.... I hope that will help your cause... thanx please rate 5 stars ....I have spent 10 minutes for ur question....thanx