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

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
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.
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education