blob: 499104165d347a30c358451e613af80eded053a2 (
plain)
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
|
package net.sven_eisenhauer.swa_prakt1;
public class ArithmeticRunner {
/**
* @param args
*/
public static void main(String[] args) {
ArithmeticVariable a = new ArithmeticVariable("a", 2);
ArithmeticVariable b = new ArithmeticVariable("b", 77);
ArithmeticVariable c = new ArithmeticVariable("c", 0.1);
ArithmeticVariable d = new ArithmeticVariable("d", 0.00003);
ArithmeticExpression aAddb = new ArithmeticAddition(a,b);
ArithmeticExpression aSubc = new ArithmeticSubstraction(a,c);
ArithmeticExpression bMuld = new ArithmeticMultiplication(b, d);
ArithmeticExpression ae1 = new ArithmeticMultiplication(aAddb, aSubc);
ArithmeticExpression ae2 = new ArithmeticSubstraction(bMuld, a);
ArithmeticExpression root = new ArithmeticAddition(ae1, ae2);
/*
try {
root.print();
System.out.println("\nResult: "+root.evaluate());
} catch (Throwable t) {
t.printStackTrace();
}
*/
try {/*
ArithmeticIterator iter = new ExpressionIterator(root);
iter.print();
System.out.println("\n");
iter = new ExpressionIterator(root);
System.out.println("\nEvaluate: "+iter.evaluate()+"\n");
*/
new PrintIter().traverse(root);
System.out.println("\n"+new EvalIter().traverse(root));
} catch (Throwable t) {
t.printStackTrace();
}
}
}
|