ChrisEvaristo / Programacao-Avancada

Expandindo Conhecimento de Programação Avancada com orientação do Professor Cunha
0 stars 0 forks source link

exemplo do professor da aula 4 #10

Open ChrisEvaristo opened 4 years ago

ChrisEvaristo commented 4 years ago

class Main { public static void main(String[] args) { try { // Creating a component tree Component component = new CompositeAccount();

      // Adding all accounts of a customer to component
      component.add(new DepositAccount("DA001", 100));
      component.add(new DepositAccount("DA002", 150));

      Component subComponent = new CompositeAccount();
      component.add(subComponent);
      subComponent.add(new SavingsAccount("SA001", 200));

      // getting composite balance for the customer
      float totalBalance = component.getBalance();
      System.out.println("Total Balance : " + totalBalance);
    }
    catch (Exception e) {
      e.printStackTrace();
    }
}

}