Question: Aim: To demonstrate advanced features of Java interfaces. Title: Polynomials. Summary: Using interfaces to hide concrete implementations of an interface using Java 8+ new features.

Aim: To demonstrate advanced features of Java interfaces.

Title: Polynomials. Summary: Using interfaces to hide concrete implementations of an interface using Java 8+ new features. Question: Write a class to store polynomials of arbitrary order, and a program that adds together two polynomials to create a third polynomial object. In this task you will create an abstract data type (ADT) to represent a mathematical polynomial. The ADT is called Poly and should comprised from an interface Poly and an implementation class QPoly. The interface has two methods, one to create QPoly objects of the type Poly and another to add to polynomial objects of type Poly (called addPoly). A quadratic polynomial has three terms at most ax2 + bx 1 + cx0 where a, b, and c can be any integer values. To store a polynomial, which will be used to represent a polynomial, all what is needed is to maintain an array of the coefficients (array = [c, b, a]). In this task, 1. Write a Poly ADT to represent a quadratic polynomial.

2. The interface should offer two services, a. make(int [] array) that returns a Poly object. b. addPoly(Poly another) that takes another Poly object, adds is to itself and returns a new Poly object.

3. Implement these services in QPoly class and add a toString() method that returns a string representation of the polynomial.

4. Write a TestPoly class with main method to test adding two polynomial objects

. a. DO NOT use the new keyword in creating instances of QPoly objects.

b. Only use Poly type.

c. Use the following test case to demo your ADT implementation

javac TestPoly

java TestPoly

p1(x) = 5x^2 + 3x - 1X^0

p2(x) = x^2 - 5x + 10X^0

p3(x) = p1 + p2

= 6x^2 - 2x + 9X^0

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!