-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPolynomialInterface.java
More file actions
32 lines (28 loc) · 1.03 KB
/
PolynomialInterface.java
File metadata and controls
32 lines (28 loc) · 1.03 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
package linkedListPolynomials;
abstract class PolynomialInterface {
DList<Term> data = null;
public PolynomialInterface() {
data = new DList<>();
}
public final String toString() {
String ans = "";
boolean starting = true;
try {
DNode<Term> n = data.getFirst();
while (n != null) {
if (!starting && n.getData().isPositive()) ans += " +";
starting = false;
ans += " " + n.getData().toString();
n = data.getNext(n);
}
} catch (Exception e) {
if (starting) return "0";
}
return ans;
}
abstract public PolynomialInterface add(PolynomialInterface p);
abstract public PolynomialInterface subtract(PolynomialInterface p);
abstract public PolynomialInterface multiply(PolynomialInterface p);
abstract public PolynomialInterface divide(PolynomialInterface p) throws Exception;
abstract public PolynomialInterface remainder(PolynomialInterface p) throws Exception;
}