-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPolynomial.java
More file actions
33 lines (27 loc) · 875 Bytes
/
Copy pathPolynomial.java
File metadata and controls
33 lines (27 loc) · 875 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
public class Polynomial {
private double coefficient;
private double exponent;
public Polynomial(double coefficient, double exponent){
this.coefficient = coefficient;
this.exponent = exponent;
}
public double calculatePoly(double x) {
final double result = this.coefficient * Math.pow(x, this.exponent);
return result;
}
public double getCoefficient() {
return this.coefficient;
}
public double getExponent() {
return this.exponent;
}
public Polynomial polynomialDerivative() {
final Polynomial polynomial;
if(this.exponent > 1) {
polynomial = new Polynomial(this.coefficient * this.exponent, this.exponent - 1);
} else {
polynomial = new Polynomial(this.coefficient, 0);
}
return polynomial;
}
}