forked from tamzid-chowdhury/Java-Polynomial-Project
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPolynomial.java
More file actions
75 lines (66 loc) · 2.35 KB
/
Polynomial.java
File metadata and controls
75 lines (66 loc) · 2.35 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
public interface Polynomial {
/**
* Returns the degree of the polynomial.
*
* @return the largest exponent with a non-zero coefficient. If all terms have zero exponents, it returns 0.
*/
int degree();
/**
* Returns the coefficient corresponding to the given exponent. Returns 0 if there is no term with that exponent
* in the polynomial.
*
* @param d the exponent whose coefficient is returned.
* @return the coefficient of the term of whose exponent is d.
*/
int getCoefficient(int d);
/**
* @return true if the polynomial represents the zero constant
*/
boolean isZero();
/**
* Returns a polynomial by adding the parameter to the current instance. Neither the current instance nor the
* parameter are modified.
*
* @param q the non-null polynomial to add to <code>this</code>
* @return <code>this + </code>q
* @throws NullPointerException if q is null
*/
Polynomial add(Polynomial q);
/**
* Returns a polynomial by multiplying the parameter with the current instance. Neither the current instance nor
* the parameter are modified.
*
* @param q the polynomial to multiply with <code>this</code>
* @return <code>this * </code>q
* @throws NullPointerException if q is null
*/
Polynomial multiply(Polynomial q);
/**
* Returns a polynomial by subtracting the parameter from the current instance. Neither the current instance nor
* the parameter are modified.
*
* @param q the non-null polynomial to subtract from <code>this</code>
* @return <code>this - </code>q
* @throws NullPointerException if q is null
*/
Polynomial subtract(Polynomial q);
/**
* Returns a polynomial by negating the current instance. The current instance is not modified.
*
* @return -this
*/
Polynomial minus();
/**
* Checks if the class invariant holds for the current instance.
*
* @return {@literal true} if the class invariant holds, and {@literal false} otherwise.
*/
boolean wellFormed();
/**
* Evaluates the polynomial for the given value of the variable.
*
* @param x the value at which to evaluate the polynomial.
* @return the result of evaluating the polynomial at the given value.
*/
double evaluate(double x);
}