Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java: For this problem you will be making your own package called mymath. This package will have two classes: Poly and PolyCalc . Both classes

Java:

For this problem you will be making your own package called mymath. This package will have two classes: Poly and PolyCalc. Both classes require complete Javadoc document comments. Also make sure you create the package and add both classes to it.

Poly:

  • This class will model a polynomial of the form: Axn-1 + Bxn-2 ... Ux3 + Wx2 + Yx + Z. It has one constructor that takes an array of double coefficients of size n (n > 0). I.e., you can assume that only non-empty arrays will be passed to the constructor.

    For example, to make the polynomial 4x2 + 3x - 2, it should be made this way new Poly(new double[]{4, 3, -2}). The same polynomial could also be made this way new Poly(new double[]{0, 0, 0, 4, 3, -2}). You are free to store these parameters however you choose.

  • Poly has a method called evaluate(). This method will return the double value of the polynomial evaluated for a given x (you can tap into java.lang.Math for some handy maths operators).
  • Poly has a method called printPoly(). This method should print the polynomial out in the form mentioned above: ax3 + bx2 + cx + d. However, terms with 0 coefficients should be omitted. For example, the polynomial 5.5x3 - 3.1x + 3 should be printed as: "5.5x^3 - 3.1x^1 + 3.0". If the Poly has all 0 coefficients, print an empty String.
  • You can define accessor methods for Poly and keep track of any other attributes you like.

PolyCalc:

  • This class will contain some calculus we can perform on a Poly object. You do not need to define a constructor. This class will behave as a utility class in the sense that we do not need to create an instance of the class to access its members. java.lang.Math is another example of this kind of class. To make this possible, we simply need to define a member as static.
  • PolyCalc has a static method called differentiate() . This method should calculate the coefficients for the derivative of the supplied Poly object. It should then create a new Poly object from those coefficients and return it. The "new coefficients" array should ALWAYS be the same length as the original array. Also, you do not need to round coefficients.
  • PolyCalc has a static method called integrate() . This method should calculate the coefficients for the integral of the supplied Poly object. It should then create a new Poly object from those coefficients and return it. Assume the integration constant C is always 0. The "new coefficients" array should ALWAYS be the same length + 1 as the original array (integrals go up an order). It does not matter if the original array is [0, 0, 0, 1], the new array should then be [0, 0, 0, 1, 0]. Also, you do not need to round coefficients.

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_2

Step: 3

blur-text-image_step3

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

More Books

Students also viewed these Databases questions

Question

2. How will the team select a leader?

Answered: 1 week ago

Question

3. What may be the goal of the team?

Answered: 1 week ago