Question
I need the code for the following problem in Java. Write a program that allows the user to create and evaluate polynomial functions of degree
I need the code for the following problem in Java.
Write a program that allows the user to create and evaluate polynomial functions of degree n.
All polynomial functions of variable x have the form
P(x) = a0 + a1x + a2x2 + + an-1xn-1 + anxn
We will assume that all of the coefficients ai and the exponents of x are integers, and the largest exponent n called the degree of the polynomial is greater than or equal to 0. For example, the polynomial
P(x) = 3 + 5x + 2x3
is of degree 3 and has coefficients a0 = 3, a1 = 5, a2 = 0, and a3 = 2. An evaluation of this polynomial with variable x = 7 should produce the result 3 + 5 x 7 + 0 x 72 + 2 x 73 = 724.
The program should accomplish each of the following tasks:
1. First, your program should interactively prompt for and read an integer value between 0 and 10 (inclusive) representing the degree of a given polynomial. Display an appropriate error message and repeat this step until a valid degree has been entered.
2. Next, your program should interactively prompt for and read signed integer values representing each of the polynomials coefficients (a0 an). Store the value of each coefficient in an array.
3. Next, your program should enter a loop that interactively reads integer values of x; for each value, your program should compute and interactively display the value of the result (P(x)) for the user-specified polynomial from step 2. Your program should then ask whether to compute P(x) for a different value of x, and repeat the process of calculating P(x) until the user says not to.
4. Finally, your program should ask the user whether he or she would like to evaluate a different polynomial, and repeat all of the above steps until the user says not to.
Your program will be expected to make use of subroutines, including (at a minimum):
1. getDegree
2. resetCoefficients
3. getCoefficients
4. evaluatePolynomial
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