Java Programming Create a class Polynomial that has the following characteristics.  Attributes degree: int - the degree of the Polynomial. Polynomial is zero, consider degree -1. If the degree given by the user is negative, multiply by -1 (you could throw and exception but we will not do it in this exercise) coefficients: int[] - array holding the coefficients of the polynomial Methods constructor with arguments for both attributes adjustPoly(): void - a method that adjusts the degree of the polynomial if the value of the coefficients of the highest degree is zero. The array of coefficients hold the coefficients corresponding to the power of the x, index 0 holds coefficient for x^0 and index length-1 holds the coefficient for x^degree. The method also adjusts the array coefficients. accessor methods for degree and coefficients evaluate(int x): int - method that evaluates the value of the Polynomial for a given value for x addPoly(Polynomial p): Polynomial - method that adds the current Polynomial object with a Polynomial p, and returns the sum of the two polynomials, as a Polynomial object. subtractPoly(Polynomial p): Polynomial - method that subtracts Polynomial p from the current object of type Polynomial derivative(): Polynomial - method that calculates the derivative of the current object of type Polynomial. equals(Polynomial p): boolean - method that returns true if the current calling object and p are equal, meaning they have same degree, and same coefficients toString(): String - method that returns a String representing the polynomial, written starting with highest power of x. Use x as variable, and ^ for the power. Sample returned String: 2x^4 - x^3 + 4x^2 + x + 5, for Polynomial object having degree=4, and coefficients={5, 1, 4, -1, 2} Create a driver class named PolynomialDriver to test the Polynomial class, in which you perform the following tasks: Define a polynomial zero, with value zero. Define and instantiate a Polynomial object p1 with degree 4, and random coefficients between 0 and 10. Define and instantiate another Polynomial object p2 with degree 3, and random coefficients between 0 and 10. Add polynomials p1 and p2 and display the result. Subtract polynomial p1 from polynomial zero, and display the result. Evaluate p1 for x=2 and display the result. Check if p1 and p2 are equal. Calculate the derivative of polynomial p1 and display the result. Run the program and capture a snapshot of the results.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Java Programming

  1. Create a class Polynomial that has the following characteristics. 
    • Attributes
      • degree: int - the degree of the Polynomial. Polynomial is zero, consider degree -1. If the degree given by the user is negative, multiply by -1 (you could throw and exception but we will not do it in this exercise)
      • coefficients: int[] - array holding the coefficients of the polynomial
    • Methods
      • constructor with arguments for both attributes
      • adjustPoly(): void - a method that adjusts the degree of the polynomial if the value of the coefficients of the highest degree is zero. The array of coefficients hold the coefficients corresponding to the power of the x, index 0 holds coefficient for x^0 and index length-1 holds the coefficient for x^degree. The method also adjusts the array coefficients.
      • accessor methods for degree and coefficients
      • evaluate(int x): int - method that evaluates the value of the Polynomial for a given value for x
      • addPoly(Polynomial p): Polynomial - method that adds the current Polynomial object with a Polynomial p, and returns the sum of the two polynomials, as a Polynomial object.
      • subtractPoly(Polynomial p): Polynomial - method that subtracts Polynomial p from the current object of type Polynomial
      • derivative(): Polynomial - method that calculates the derivative of the current object of type Polynomial.
      • equals(Polynomial p): boolean - method that returns true if the current calling object and p are equal, meaning they have same degree, and same coefficients
      • toString(): String - method that returns a String representing the polynomial, written starting with highest power of x. Use x as variable, and ^ for the power. Sample returned String: 2x^4 - x^3 + 4x^2 + x + 5, for Polynomial object having degree=4, and coefficients={5, 1, 4, -1, 2}
  2. Create a driver class named PolynomialDriver to test the Polynomial class, in which you perform the following tasks:
    • Define a polynomial zero, with value zero.
    • Define and instantiate a Polynomial object p1 with degree 4, and random coefficients between 0 and 10.
    • Define and instantiate another Polynomial object p2 with degree 3, and random coefficients between 0 and 10.
    • Add polynomials p1 and p2 and display the result.
    • Subtract polynomial p1 from polynomial zero, and display the result.
    • Evaluate p1 for x=2 and display the result.
    • Check if p1 and p2 are equal.
    • Calculate the derivative of polynomial p1 and display the result.
  3. Run the program and capture a snapshot of the results.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 7 images

Blurred answer
Knowledge Booster
Reference Types in Function
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-engineering and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY