-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathOperation.java
More file actions
40 lines (33 loc) · 754 Bytes
/
Operation.java
File metadata and controls
40 lines (33 loc) · 754 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
34
35
36
37
38
39
40
/**
* CS2030S PE1 Question 1
* AY20/21 Semester 2
*
* @author A0238768J
*/
abstract class Operation implements Expression {
private Expression e1;
private Expression e2;
public Operation(Expression e1, Expression e2) {
this.e1 = e1;
this.e2 = e2;
}
@Override
public abstract Object eval() throws InvalidOperandException;
public static Operation of(char c, Expression e1, Expression e2) {
if (c == '*') {
return new Multiply(e1, e2);
} else if (c == '+') {
return new Concatenate(e1, e2);
} else if (c == '^') {
return new Xor(e1, e2);
} else {
return null;
}
}
public Expression getFirst() {
return e1;
}
public Expression getSecond() {
return e2;
}
}