Question
[JAVA]Your assignment is to write a class called Polynomial. A polynomial is a function of the following form: f(n) = ck nk + ck-1 nk-1
[JAVA]Your assignment is to write a class called Polynomial. A polynomial is a function of the following form: f(n) = ck nk + ck-1 nk-1 + + c1 n + c0 c0, c1, c2, , ck are called coefficients. We call k the degree of the polynomial. For our purposes, we will assume that the coefficients are all integers (positive, negative, or 0). The coefficient ck should be nonzero. I have placed a file named hw1.jar in the D2L Homework assignment 1 dropbox folder. It contains 2 source files called Polynomial.java and TestHW1.java. You may use the code in Polynomial.java as a starting point for your program, or if you prefer you can write your own code from scratch. The TestHW1 class tests the methods of the Polynomial class on a few cases. Please upload the Polynomial.java file once you have completed it. I recommend that you store the coefficients of a Polynomial object in an instance variable which is an array of integers. You should write the following methods for the Polynomial class: a. (1/2 point) A constructor. It is passed 1 parameter: an array of integers which represents the coefficients of the polynomial. b. (1 point) A method called simplify. It is a void method which is passed 0 parameters. It ensures that the polynomials kth coefficient is not 0. If a polynomial is created which has no non-zero coefficients, then it should be represented as an array of length 0. The simplify method should be called within the constructor. c. (2 points) A toString method. As is usually the case in Java, toString is passed 0 parameters and returns a String representation of an object. Examples of the kind of string that toString should return for polynomials can be found below. d. (1/2 point) A degree method. It returns an integer, which is the degree of the polynomial. e. (1 point) An evaluate method. It is passed 1 parameter x, which is an integer. It should return an integer, which represents f(x), the value of the polynomial f(n) when n is equal to x.
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