1
2
3
4
5
6
7
8public
9class Mult extends BinaryExpr {
10
11
12
13 public
14 Mult(Expr left, Expr right) {
15 super(left, right);
16 }
17
18
19
20 public
21 Object eval() {
22
23
24
25 Object value1
26 = left.eval();
27
28 Object value2
29 = right.eval();
30
31
32
33 if ( value1 instanceof Integer
34 &&
35 value2 instanceof Integer ) {
36
37 return
38 new Integer( ((Integer)value1).intValue()
39 *
40 ((Integer)value2).intValue() );
41 }
42
43
44
45 if ( value1 instanceof Double
46 &&
47 value2 instanceof Double ) {
48
49 return
50 new Double( ((Double)value1).doubleValue()
51 *
52 ((Double)value2).doubleValue() );
53 }
54
55
56
57 throw
58 new IllegalArgumentException(" * : illegal operand types");
59 }
60
61
62
63 public
64 String toString() {
65 return
66 "(" + left.toString() +
67 " * " + right.toString() +
68 ")";
69 }
70}
71
72
73