Create a class polynomial that is used to evaluate a polynomial function of x:
P(x) = a0 + a1x + a2x + ⋯ + an−1xn−1 + anxn
The coefficients ai are floating-point numbers, the exponents of x are integers, and the largest exponent n—called the degree of the polynomial—is greater than or equal to 0. The class has the attributes
■ degree —the value of the largest exponent n
■ coefficients —an array of the coefficients ai
and the following methods:
- Polynomial (max) —a constructor that creates a polynomial of degree max whose coefficients are all 0
- setConatant (i, value) —Sets the Coefficient ai to value
- evaluate (x) — returns the value of the polynomial for the given value x
For example, the polynomial
P(x) = 3 + 5x + 2x3
is of degree 3 and has coefficients a0 = 3, a1 = 5, a2 = 0, and a3 = 2. The invocation evaluate (7) computes 3 + 5 × 7 + 0 × 7 + 2 = 73, which is 3 + 35 + 0 + 686, and returns the result 724.
Want to see the full answer?
Check out a sample textbook solutionChapter 7 Solutions
Java : Introduction To Prob...-MyProgrammingLab
Additional Engineering Textbook Solutions
Starting Out with Programming Logic and Design (4th Edition)
Artificial Intelligence: A Modern Approach
C++ How to Program (10th Edition)
C Programming Language
Starting Out with Java: From Control Structures through Data Structures (3rd Edition)
Computer Systems: A Programmer's Perspective (3rd Edition)
- suppose there is a class Roster. Roster has one variable, roster, which is a list of tuples containing the names of students and their numerical grades- for example, [('Richard',90), ('Belle',67), ('Christine',85), ('Francine',97)]. Roster has a function findValedictorian that returns the name of the student with the highest grade. Find the valedictorian of the Roster object englishClass and store it in the variable valedictorian.arrow_forwardsuppose there is a class Roster. Roster has one variable, roster, which is a list of tuples containing the names of students and their numerical grades- for example, [('Richard',90), ('Belle',67), ('Christine',85), ('Francine',97)]. Roster has a function called calculateAverage that calculates the average of the students in their roster. Write a statement that returns the average of the Roster object englishClass, which has already been defined. using pythonarrow_forwardYou are required to build a class ArithematicProblem that represent a binaryarithematic problem such as addition, subtraction, multiplication and division.The ArithematicProblem class is a super class which is there to provide the mostgeneric version of the ArithematicProblem concept. This class has followinginstance variables1. Operator1 (double)2. Operator2 (double)3. Answer(double)4. Error(boolean)The value of Operator1 and Operator2 will be initialized through parameters in theconstructor while the value of answer is Double.POSITIVE_INFINITY and error is falseby default.Provide getters for all but setters for only operand1 and operand2Provide the toString method so that the string representation of each operationthe standard representation in mathematics i.e. if its an addition problem then itshould be printed as 2 + 3 = 5 and so on.Provide a method double solve() in this class. This method performs the arithematicoperation on the operands, calculates answer, sets the value of…arrow_forward
- An arithmetic progression is a sequence of numbers such that the difference between the consecutive terms is constant. For instance, the sequence 5, 7, 9, 11, 13, 15 is an arithmetic progression with a common difference of 2.Given the class IntNumber:1 public class IntNumber2 {3 public final int value;45 public IntNumber(int number) {6 this.value = number;7 }8 }where value is an immutable field, that can be directly accessed (public), implement a class called ArithmeticProgressionthat implements the following methods:•1 public static IntNumber getArithmeticProgressionDifference(ArrayList<IntNumber> list)which returns the difference between terms of the arithmetic progression (as an object of type IntNumber) if thevalues of the IntNumber objects are an arithmetic progression. The method returns null in any other case.•1 public static void printIsArithmeticProgression(ArrayList<IntNumber> list)which prints on the console:The list is an arithmetic progression with difference =…arrow_forwardAn arithmetic progression is a sequence of numbers such that the difference between the consecutive terms is constant. For instance, the sequence 5, 7, 9, 11, 13, 15 is an arithmetic progression with a common difference of 2. Given the class IntNumber: 1. public class IntNumber 2. { 3. public final int value; 4. 5. public IntNumber(int number) { 6. this.value = number; 7. } 8. } where value is an immutable field, that can be directly accessed (public), implement a class called ArithmeticProgression that implements the following methods: •1 public static IntNumber getArithmeticProgressionDifference(ArrayList< IntNumber> list) which returns the difference between terms of the arithmetic progression (as an object of type IntNumber) if the values of the IntNumber objects are an arithmetic progression. The method returns null in any other case. • public static void printIsArithmeticProgression(ArrayList<IntNumber> list ) which prints on the console: The list is an arithmetic…arrow_forwardA java program, with a class Rectangle with attributes length and width , each of which defaults to 2. Providemethods that calculate the rectangle’s perimeter and area. It has set and get methods for bothlength and width . The set methods should verify that length and width are each floating-pointnumbers larger than 10.0 and less than 40.0. Write a program to test class Rectangle .arrow_forward
- We have a parking office class for an object-oriented parking management system using java Add (implement )a function to the Parking Office class to return a collection of customer ids (getCustomerIds) using java I have attached two class diagrams with definitions of all related classes in our system (i.e car, customer, .....). N.B. Parking office methods in the class definition like register, getcustomer and addcharge have already been implemented, we just need an additional getcustomerID function as mentioned above Explain the code you wrote with a few wordsarrow_forwardJava - Polymorphism Create a class named “Shape” that has the abstract methods getArea() and getPerimeter(). Create classes named “Rectangle”, “Square”, and “Circle”. Override the methods getArea() and getPerimeter() with the right equation in getting the area and perimeter. For rectangle, create attribute length and width. For square, side. For circle, radius. Inputs 1. Char input for Shape type (R/S/C) 2. Dimensions of specific type of Shape C 5 Sample Output Shape(R/S/C): R Length: 10 Width: 50 Area: 500.00 Perimeter: 120.00arrow_forwardPython: implement a class called point, the class contains two values of a type of integer (x and y). Define both as private. Add the following to the class: 1. Default initializer, used to create objects of type Point, by default x and y are set to 1. 2. Initializer with two parameters for x and y. 3. Set and get methods for x 4. Set and get methods for y 5. Method __str__, which returns a string that represent the Point(e.g., p = [4,5])arrow_forward
- Implement the Solver class. The point of the solver class is the solve method which takes a board/puzzle configuration represented as a 2D array of bytes and returns a byte array containing a minimal sequence of moves that will lead to the solved board. The 2D array of bytes is “triangular” and represents a valid board configuration. Namely, the 2D array has 5 rows (0 – 4) and the size of every row is 1 more than its index.The array contains one 0, five 1s, four 2s and five 3s. The solve method then returns an array of bytes representing a minimal sequence of moves that solves the puzzle. In other words, if the numbers from the returned array are used in order as inputs to the move method on the Board object representing the initial configuration, the resulting board configuration represents the solved board. If the input to the solve method is a board configuration that is already solved, then solution requires no moves and an array of size 0 must be returned. impliment the solver…arrow_forwardImplement the Solver class. The point of the solver class is the solve method which takes a board/puzzle configuration represented as a 2D array of bytes and returns a byte array containing a minimal sequence of moves that will lead to the solved board. The 2D array of bytes is “triangular” and represents a valid board configuration. Namely, the 2D array has 5 rows (0 – 4) and the size of every row is 1 more than its index.The array contains one 0, five 1s, four 2s and five 3s. The solve method then returns an array of bytes representing a minimal sequence of moves that solves the puzzle. In other words, if the numbers from the returned array are used in order as inputs to the move method on the Board object representing the initial configuration, the resulting board configuration represents the solved board. If the input to the solve method is a board configuration that is already solved, then solution requires no moves and an array of size 0 must be returned. import…arrow_forwardImplement the Solver class. The point of the solver class is the solve method which takes a board/puzzle configuration represented as a 2D array of bytes and returns a byte array containing a minimal sequence of moves that will lead to the solved board. The 2D array of bytes is “triangular” and represents a valid board configuration. Namely, the 2D array has 5 rows (0 – 4) and the size of every row is 1 more than its index.The array contains one 0, five 1s, four 2s and five 3s. The solve method then returns an array of bytes representing a minimal sequence of moves that solves the puzzle. In other words, if the numbers from the returned array are used in order as inputs to the move method on the Board object representing the initial configuration, the resulting board configuration represents the solved board. If the input to the solve method is a board configuration that is already solved, then solution requires no moves and an array of size 0 must be returned. import…arrow_forward
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning