bartleby

Videos

Expert Solution & Answer
Book Icon
Chapter 7, Problem 12E

Explanation of Solution

The complete implementation for “Polynomial” class is given below:

//Define "Polynomial" class

public class Polynomial

{

    //Declare required variables   

    private int degree;

    private double[] coefficients;

/* Constructor for "Polynomial" class with argument "max" */

    public Polynomial(int max)

    {

        degree = max;

        coefficients = new double[degree+1];

    }

/* Define method for set the coefficient "a" to "value" */

    public void setConstant(int i, double value)

    {

/* If the value of "i" is greater than or equal to "0" and value of "i" is less than or equal to "degree", then */

        if(i >= 0 && i <= degree)

/* Set given coefficient to given "value" */

            coefficients[i] = value;

    }

/* Define method for returns the polynomial value for given "x" */

    public double evaluate(double x)

    {

        /* Set total to "0" */

        double total = 0.0;

        /* Set the value of x to "1" */

        double xValue = 1.0;

        /* Compute sum for given equation */

        for(int i = 0; i <= degree; i++)

        {

            total += coefficients[i]*xValue;

            xValue *= x;

        }

/* Returns the sum of given polynomial equation for given "x" */

        return total;

    }

    //Define main function

    public static void main(String[] args)

    {

        /* Create object for "Polynomial" class */

        Polynomial p1 = new Polynomial(5);

/* Set a0 = 3 by calling the method "setConstant" */

        p1...

Blurred answer
Students have asked these similar questions
2. Perform resource allocation for the following project. Resource limits are 6 labors and 2 helpers. Legend: Activity Dur Resources G H 2 3 2L 1H 2L OH A 1 3L 1H + B D F J K 3 4 6 2 4 4L 2H 3L OH 4L 1H 2L 2H 4L 2H C E 2 2 I 1 2L 1H 3L 1H 5L 1H
Need Java method please. Thank you.
Need Java method please. Thank you.

Chapter 7 Solutions

Java: An Introduction to Problem Solving and Programming plus MyProgrammingLab with Pearson eText -- Access Card Package (7th Edition)

Additional Engineering Textbook Solutions

Find more solutions based on key concepts
The tension in cables AB, BC, and CD and the angle (θ).

INTERNATIONAL EDITION---Engineering Mechanics: Statics, 14th edition (SI unit)

“toString()” method for given class: //Definition of "toString()" public String toString() { //Declare the vari...

Starting Out with Java: From Control Structures through Objects (7th Edition) (What's New in Computer Science)

the normal strain εAB,εAC,εBC, and (γA)xy .

Mechanics of Materials (10th Edition)

Knowledge Booster
Background pattern image
Computer Science
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
Text book image
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
Text book image
Systems Architecture
Computer Science
ISBN:9781305080195
Author:Stephen D. Burd
Publisher:Cengage Learning
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Text book image
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
Call By Value & Call By Reference in C; Author: Neso Academy;https://www.youtube.com/watch?v=HEiPxjVR8CU;License: Standard YouTube License, CC-BY