Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

3 / 130 mA Question 2 (Polynomial.java and PolynomialTester.java) Although it is quite advanced in many ways, the Equinox's main computer needs to be tested

image text in transcribed
image text in transcribed
image text in transcribed
3 / 130 mA Question 2 (Polynomial.java and PolynomialTester.java) Although it is quite advanced in many ways, the Equinox's main computer needs to be tested for some simple algebraic functionality ahead of the next research mission to planet Frobus 3. You have been tasked with writing a class called Polynomial that represents and evaluates polynomial expressions From your cadet training, you recall that a polynomial function of x takes the form Px)= 4, + ax+ax +.+a_**!tax where coefficients a, are floating-point (decimal) numbers, the exponents of x are integers, and the largest exponent called the degree of the polynomial is greater than or equal to zero. It sounds complicated but it might not be as bad as you think. Your Java class is defined by two data fields, one that represents the degree of the polynomial (the value of largest exponent n) and the other is a 1D array of coefficients al. Thus if the value of n is 4 and the coefficients in the array are in order) 7.2.5.0.1 the corresponding polynomial is 7+2x+5x+x* Coefficients can be integers or doubles. Below is the UML diagram for this class: SSSSSSSSS ISENOSSESS Polynomial -degree in S OS -coefficient double Polynomial (deg Tin Polynomial Polynomial set.coefficient index int, Valse double get coefficient indexint) 1 double -evaluate double double tostring) string equals ob object boolean Here are some extra hints to help you along EER Polynomial (deg i int) this is an argumented constructor that creates a new polynomial object with degree deg The coefficients will all be 0 after the object is created Polynomial (Pr Polynomial this is a copy constructor. It should take an existing polynomial object as an argument and should create a new one with the same degree and coefficients. setCoefficient.getObertalent should be straightforward (I think?!). Note: If the user enters invalid indices, do nothing (change no coefficient value, get no coefficient value) evaluate (x : double) this method renuns the computed value of the polynomial given the value of argument. If we use our previous example polynomial 742x45x+x the value of this polynomial for a value of x-3 would be: 7+2(3)+5(3) + (3)=139. You'll need a loop to access all of the coefficients. L IBRI Edit View Window Help @MO cosc1046-a1-w20.pdf sc1046-a1-w20... * 1 Q 4 / 13 Amy 81.1% - equals (obj2): compares to Polynomials (or a polynomial and another object) for equality. Two polynomials are considered equal IFF they have the same degree and all the same coefficients in the same order) toString(): displays a polynomial to the console (see sample output on next page). Use a loop to constructor your Write JavaDocs for the Polynomial class (not the tester). REMEMBER - your tester class will do the input and output work; it will make use of your object. There should be NO Scanners in the Polynomial class. Keep your methods generalized - data comes in through arguments and out through return statements. a 4/13 81.1% - Write an application class called PolynomialTester that accomplishes the following: Prompt the user to enter the degree of the desired polynomial. Call your constructor and create the basic polynomial. At least make sure that the degree is positive and greater than zero (ie, input validation) Prompt the user to enter all the necessary coefficients. Use a loop and your setCoefficient method to set the coefficients for your polynomial. Display the completed" polynomial Prompt the user to enter in a value for x (double or int are both fine). Evaluate the polynomial for that value of x and display the result. Use a sentinel loop to re-prompt the user to enter other values of x and to keep computing the evaluated polynomial until they enter the string quit Before quitting, create a copy of the polynomial using your copy constructor. Show that they are equal using your equals() method and by printing them both out to the screen. Then allow the user to change one coefficient of their choice and show that they are different (use equals() and display to the screen). This is not shown in the sample output below. Write proper Java docs for your Polynomial.java source file and write normal comments for your tester. Enter polynomial degree: Coeff for degree 0:2 Coeff for degree 1:2 Coeff for degree 2: 5 Coeff for degree 3: 0 Coeff for degree 4: 1 Polynomial: 7.0 + (2.0)x1 + (5.0) x^2 + (1.0) x^4 Enter a value of x for which to evaluate the polynomial: 3 For x = 3, polynomial = 139.0 Enter a value of x for which to evaluate the polynomial-3. For x = -3.1, polynomial = 141.2021 Enter a value of x for which to evaluate the polynomial: 9.26 For x = 9.26, polynomial = 7806.9089057599995 Enter a value of x for which to evaluate the polynomial! cruit

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_2

Step: 3

blur-text-image_3

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

Database Systems Introduction To Databases And Data Warehouses

Authors: Nenad Jukic, Susan Vrbsky, Svetlozar Nestorov

1st Edition

1943153191, 978-1943153190

More Books

Students also viewed these Databases questions

Question

What is Larmors formula? Explain with a suitable example.

Answered: 1 week ago