Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ajuste style #91

Merged
merged 2 commits into from
Jun 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion design-patterns-java/src/br/com/alura/loja/TesteImposto.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import br.com.alura.loja.imposto.CalculadoraDeImpostos;
import br.com.alura.loja.imposto.ISS;
import br.com.alura.loja.imposto.ICMS;
import br.com.alura.loja.orcamento.Orcamento;
import java.math.BigDecimal;

Expand All @@ -10,6 +11,8 @@ public class TesteImposto {
public static void main(String[] args) {
Orcamento orcamento = new Orcamento(new BigDecimal("100"), 1);
CalculadoraDeImpostos calculadoraDeImpostos = new CalculadoraDeImpostos();
System.out.println(calculadoraDeImpostos.calcular(orcamento, new ISS()));
System.out.println(calculadoraDeImpostos.calcular(orcamento, new ISS(new ICMS(null))));
System.out.println(calculadoraDeImpostos.calcular(orcamento, new ISS(null)));
System.out.println(calculadoraDeImpostos.calcular(orcamento, new ICMS(null)));
}
}
8 changes: 6 additions & 2 deletions design-patterns-java/src/br/com/alura/loja/imposto/ICMS.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@
import br.com.alura.loja.orcamento.Orcamento;
import java.math.BigDecimal;

public class ICMS implements Imposto {
public class ICMS extends Imposto {

public BigDecimal calcular(Orcamento orcamento) {
public ICMS(Imposto outro) {
super(outro);
}

public BigDecimal realizarCalculo(Orcamento orcamento) {
return orcamento.getValor().multiply(new BigDecimal("0.1"));
}
}
13 changes: 0 additions & 13 deletions design-patterns-java/src/br/com/alura/loja/imposto/ICMSComISS.java

This file was deleted.

8 changes: 6 additions & 2 deletions design-patterns-java/src/br/com/alura/loja/imposto/ISS.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@
import br.com.alura.loja.orcamento.Orcamento;
import java.math.BigDecimal;

public class ISS implements Imposto {
public class ISS extends Imposto {

public BigDecimal calcular(Orcamento orcamento) {
public ISS(Imposto outro) {
super(outro);
}

public BigDecimal realizarCalculo(Orcamento orcamento) {
return orcamento.getValor().multiply(new BigDecimal("0.06"));
}
}
22 changes: 19 additions & 3 deletions design-patterns-java/src/br/com/alura/loja/imposto/Imposto.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,24 @@
import br.com.alura.loja.orcamento.Orcamento;
import java.math.BigDecimal;

public interface Imposto {
public abstract class Imposto {

BigDecimal calcular(Orcamento orcamento);
private Imposto outro;

}
public Imposto(Imposto outro) {
this.outro = outro;
}

protected abstract BigDecimal realizarCalculo(Orcamento orcamento);

public BigDecimal calcular(Orcamento orcamento) {

BigDecimal valorImposto = realizarCalculo(orcamento);
BigDecimal valorDoOutroImposto = BigDecimal.ZERO;

if (outro != null) {
valorDoOutroImposto = outro.realizarCalculo(orcamento);
}
return valorImposto.add(valorDoOutroImposto);
}
}