public static void main(String[] args) {
    Leaf a = new Leaf(5);
    Leaf b = new Leaf(3);
    Leaf c = new Leaf(2);
    Leaf d = new Leaf(6);

    Composite mul = new Composite(Operator.mul, a, b);

    Composite div = new Composite(Operator.div, mul, c);

    Composite plus = new Composite(Operator.plus, div, d);
    plus.operation();
  }
Exemple #2
0
  public static void main(String[] args) {

    Composite root = new Composite("Root");

    Component a = new Leaf("A");

    Composite b = new Composite("B");
    Component b1 = new Leaf("B-1");
    Component b2 = new Leaf("B-2");
    Component b3 = new Leaf("B-3");
    b.addChild(b1);
    b.addChild(b2);
    b.addChild(b3);

    Component c = new Leaf("C");

    root.addChild(a);
    root.addChild(b);
    root.addChild(c);

    root.operation();
  }