Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

MAKE THIS PROGRAM IN JAVA Milestone 1: The Polynomial Object poly This is where students get a chance to make your own object. This object

MAKE THIS PROGRAM IN JAVA

image text in transcribed

Milestone 1: The Polynomial Object poly This is where students get a chance to make your own object. This object will behave like a polynomial in standard form. Polynomials in standard form have a general form: f(x) = apx" + aix"-1 + a2xn-2 +...+an-222 +On-1X + an For a list of coefficients of the form: ao,a1, 22, ... An-2, an-1, an An example would be something like: f() = 32 -2 +1122 - 77 +11 for the coefficients 3, -2, 11, -7, 11. Another example would be: (z) = 1&+ 111? +6 for the coefficients 18, 0, 0, 11, 0, 6. Notice in this last example that a "0" is part of the input string to the constructor if there are missing terms. Thus, a polynomial such as f (x) = x would require the input string "1 OOOOOOOO". Your object might generate the array as if you have the polynomial f(x) = x8 + Ox? +0x + 0x + 0x4 + 0x3 + 0x +0x1 +0, but this is the same thing as f(x) = x, and should still generate the values you - expect. In other words, it shouldn't change your results to treat the zeroes as valid terms. Your object detern the order the polynomial as being the size of the array minus one. If the array is: 1, 0, 0, 0, 0, 0, 0, 0, 0 then there are 9 terms, so the polynomial is order 8, meaning the highest power of x will be 8 and the result will be the function f(x) = 28. This object (which we will name poly for this description (you can give it your own appropriate name)), which mimics a given polynomial function, must take as a constructor a string representing the coefficients of a polynomial, separated by spaces. Example: "-2 3 5 -9 12". We are only considering whole-number coefficients for this assignment. There can be as many as 8 coefficients (order 7) or as few as 1 la constant function - order O). . A call to the constructor with a string expr (or use your own appropriate name) would look like either: poly px = new poly ("-2 3 5 9 12"), or: poly px = new poly (expr) If expr = "-2 3 5 9 12", then both calls shown above should have the same result. the string expr could take a Scanner input using nextLine() When I implemented this, the constructor separated them into an array of string: "-2", "3", "5", "-9", "12". This can be done using, on a string with a name like param, a function like . param.split(" "), which splits a string along the spaces (or whatever substring is passed into the split() function). This array of string is converted into an array of integer:-2, 3, 5, -9, 12. . This can use a runtime object called Integer, which does not need to be declared. . If s is an array of string, then the ith coefficient in a previosuly declared array of integer iarr can be produced from the ith member of the string array as follows (inside a counted loop such as a for loop): . iarr[i] = Integer.parseInt(s[i]); The array of integer, array of string, size of the array, lead term, and constant term are internal to the object, and declared private. The constructor sets all of these values from the original input string expr (or an otherwise appropriately-named variable). The rest of the object interface consists of: getLead() -- a getter function for the lead term - returns integer. It takes no parameters. o getConst() - a getter function for the constant term. It takes no parameters. getorder() -- a getter function for the polynomial order. It takes no parameters. The order of the polynomial is number of terms passed into the constructor minus 1. f(double x) -- a function which returns the value of the polynomial for some x. The value returned will be of type double. . Most of these functions are simple and consist of not much more than a return statement. of(x) will require more thought and coding. I have implented f(x) using a for loop to go through the array of coefficients, multiplied by decreasing powers of x, from the polynomial order and counting down to an exponent of O. A driver was provided in the Content section, and is repeated below. The content section provides the same source code, with more comments (they were cut out below for brevity). Read the comments in the comment section (and the ones here) before using. Test the values generated by your program against your own calculations. import java.util.Scanner; class Main public static void main(String[] args) { Scanner sc - new Scanner(System.in); System.out.print("Please input a set of numbers: "); String scoeff - sc.nextLine(); // inputs a list of coefficients as a single string poly - new poly(scoeff); // calls the constructor using the input string System.out.printf("Lead ters: %d ", p.getLead()); System.out.printf("Constant term: %d ", p.getConst(); Systen.out.printf("Order: %d ", p.getorder); Systen.out.printf("Y-intercept: (8, %d) ", (int) p.f()); for (int x = 1; x 0, and knowing that there are no breaks in the function, there has to be a value in between a and b that crosses the x axis. In other words, there exists a value = = c where a

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

DB2 11 The Database For Big Data And Analytics

Authors: Cristian Molaro, Surekha Parekh, Terry Purcell, Julian Stuhler

1st Edition

1583473858, 978-1583473856

More Books

Students also viewed these Databases questions

Question

LO14.1 Describe the characteristics of oligopoly.

Answered: 1 week ago