exo6: add the full implementation.
[Project_POO.git] / exo6 / Main.java
CommitLineData
c7043054 1import java.util.Map.Entry;
dd8febe8
JB
2
3class Main {
4
5 /**
6 * The main() function
7 * @param String[] args main() function arguments array
8 */
9 public static void main(String[] args) {
c7043054
JB
10 System.out.println("-----");
11 String exp = "5 + x";
12 try {
13 Variable x = new Variable();
14 Expression ArithmeticExpression = new Opplus(new Chiffre('5'), x);
15 while (true) {
16 Entry<Integer, Double> e = x.getFirstEntry();
17 System.out.println("x = " + e.getValue() + " :");
18 System.out.println(exp + " = " + ArithmeticExpression.evaluer());
19 }
20 }
21 catch (Exception e) {}
22
23 System.out.println("-----");
24 exp = "(3 + 2*x)*(7/y - 2) - 5/(3*z + 4)";
25 try {
26 Variable x = new Variable();
27 Variable y = new Variable();
28 Variable z = new Variable();
29 Expression ParentheseOne = new ParentheseExp(new Opplus(new Chiffre('3'), new Opmulti(new Chiffre('2'), x)));
30 Expression ParentheseTwo = new ParentheseExp(new Opminus(new Opdiv(new Chiffre('7'), y), new Chiffre('2')));
31 Expression ParentheseThree = new ParentheseExp(new Opplus(new Opmulti(new Chiffre('3'), z), new Chiffre('4')));
32 Expression ArithmeticExpression = new Opminus(new Opmulti((Facteur)ParentheseOne, (Terme)ParentheseTwo), new Opdiv(new Chiffre('5'), (Terme)ParentheseThree));
33 while (true) {
34 Entry<Integer, Double> e = x.getFirstEntry();
35 System.out.println("x = y = z = " + e.getValue() + " :");
36 System.out.println(exp + " = " + ArithmeticExpression.evaluer());
37 }
38 }
39 catch (Exception e) {}
dd8febe8
JB
40 }
41}