What is the Java interface and how do I code it?

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter10: Classes And Data Abstraction
Section: Chapter Questions
Problem 19PE
icon
Related questions
Topic Video
Question
What is the Java interface and how do I code it?
An example of such a polynomial is f(x)=3x- 5x+ 2x – 4. This polynomial has four terms.
The degree of a polynomial is defined as the highest power of the variable in a term. In the above
example, the degree of the polynomial is 4. The polynomials we deal with have only positive, integral
powers. The coefficients of our polynomials are also integral numbers.
Two polynomials are the same if they contain the same terms.
Several algebraic operations are possible with polynomials. The simplest one is evaluating the
polynomial for a specific value of the variable. For example, for a polynomial f(x)=3x- 5x+ 2x – 4,
its value at x=2.5 is defined as: £(2.5) = 3 * (2.5)- 5 * (2.5)+ 2 * (2.5) – 4 which is 40.0625.
Polynomials can be added together to create a new polynomial. The addition is performed by
combining all the terms and adding the coefficients of the terms with the same power. For
example 3x- 5x+ 2x – 4 + 2x + 2x + 4 = 3x – 3x+ 2x+ 2x.
The degree of the sum is the maximum of the degrees of the two polynomials.
2mWbat to do
Design an interface Polynomial that defines the above operations. This is your polynomial abstract
data type and specifies the contract Polynomial (s) will adhere to. Specifically this interface
should have the following method signatures:
A method addTerm that takes a coefficient and a power (both integral numbers) and adds the
resulting term to the polynomial. (This will enable you to build a polynomial term-by-term.) It
should throw an T1legalaraumentExsertioa if a negative power is passed to it.
A method remove Term that takes a power and removes any and all terms in the polynomial with
that power.
A method getRearse that returns the degree of this polynomial.
A method getCoefficient that takes a power and returns the coefficient for the term with that
power.
A method evaluate that takes a double-precision decimal number and returns a double-
precision result.
A method add that takes another Polynomial object and returns the polynomial obtained by
adding the two polynomials. Any implementation should ensure that this method does not
mutate either polynomial. The implementation may assume that the given Polynomial is the of the
same concrete class as this object; if it is a different class, the method may throw
Now implement this interface in a class BolyAAuialuel. Beyond implementing
the Polynomial interface, this implementation should have the following features/obey these
constraints:
This class should store the polynomial using theAa linked list with nodes. This representation
must be implemented by you (i.e. you are not allowed to use existing List classes in Java).
Transcribed Image Text:An example of such a polynomial is f(x)=3x- 5x+ 2x – 4. This polynomial has four terms. The degree of a polynomial is defined as the highest power of the variable in a term. In the above example, the degree of the polynomial is 4. The polynomials we deal with have only positive, integral powers. The coefficients of our polynomials are also integral numbers. Two polynomials are the same if they contain the same terms. Several algebraic operations are possible with polynomials. The simplest one is evaluating the polynomial for a specific value of the variable. For example, for a polynomial f(x)=3x- 5x+ 2x – 4, its value at x=2.5 is defined as: £(2.5) = 3 * (2.5)- 5 * (2.5)+ 2 * (2.5) – 4 which is 40.0625. Polynomials can be added together to create a new polynomial. The addition is performed by combining all the terms and adding the coefficients of the terms with the same power. For example 3x- 5x+ 2x – 4 + 2x + 2x + 4 = 3x – 3x+ 2x+ 2x. The degree of the sum is the maximum of the degrees of the two polynomials. 2mWbat to do Design an interface Polynomial that defines the above operations. This is your polynomial abstract data type and specifies the contract Polynomial (s) will adhere to. Specifically this interface should have the following method signatures: A method addTerm that takes a coefficient and a power (both integral numbers) and adds the resulting term to the polynomial. (This will enable you to build a polynomial term-by-term.) It should throw an T1legalaraumentExsertioa if a negative power is passed to it. A method remove Term that takes a power and removes any and all terms in the polynomial with that power. A method getRearse that returns the degree of this polynomial. A method getCoefficient that takes a power and returns the coefficient for the term with that power. A method evaluate that takes a double-precision decimal number and returns a double- precision result. A method add that takes another Polynomial object and returns the polynomial obtained by adding the two polynomials. Any implementation should ensure that this method does not mutate either polynomial. The implementation may assume that the given Polynomial is the of the same concrete class as this object; if it is a different class, the method may throw Now implement this interface in a class BolyAAuialuel. Beyond implementing the Polynomial interface, this implementation should have the following features/obey these constraints: This class should store the polynomial using theAa linked list with nodes. This representation must be implemented by you (i.e. you are not allowed to use existing List classes in Java).
Expert Solution
Explanation
  • The interface in Java is a system to accomplish deliberation. There can be just theoretical techniques in the Java interface, not strategy body. It is utilized to accomplish deliberation and different legacy in Java. As such, you can say that interfaces can have theoretical strategies and variables. 
  • An interface is a device or a framework that disconnected elements use to associate. In contrast to a class, an interface never executes techniques; all things considered, classes that actualize the interface actualize the strategies characterized by the interface. A class can actualize various interfaces.
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Instruction Format
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning