Skip to content

Instantly share code, notes, and snippets.

@alexduarte
Created December 20, 2011 21:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save alexduarte/1503287 to your computer and use it in GitHub Desktop.
Save alexduarte/1503287 to your computer and use it in GitHub Desktop.
public abstract class Imposto {
private final Imposto outroImposto;
public Imposto(Imposto outroImposto){
this.outroImposto = outroImposto;
}
public Imposto(){
this.outroImposto = null;
}
protected double calculoDoOutroImposto(Orcamento orcamento) {
if(outroImposto==null)return 0;
return outroImposto.calcula(orcamento);
}
public abstract double calcula(Orcamento orcamento);
}
public class ICMS extends Imposto {
public ICMS(){}
public ICMS(Imposto outroImposto) {
super(outroImposto);
}
public double calcula(Orcamento orcamento) {
return orcamento.getValor()*0.05 + calculoDoOutroImposto(orcamento);
}
}
public class ICCC extends Imposto {
public ICCC(){}
public ICCC(Imposto outroImposto) {
super(outroImposto);
}
public double calcula(Orcamento orcamento) {
if(orcamento.getValor()<1000.0){
return orcamento.getValor()*0.05 + calculoDoOutroImposto(orcamento);
}
if(orcamento.getValor()>=1000.00 && orcamento.getValor()<= 3000.0) {
return orcamento.getValor()*0.07 + calculoDoOutroImposto(orcamento);
}
if(orcamento.getValor()>3000.0){
return orcamento.getValor()*0.08 + 30.0 + calculoDoOutroImposto(orcamento);
}
return 0;
}
}
public class ISS extends Imposto {
public ISS(){}
public ISS(Imposto outroImposto) {
super(outroImposto);
}
public double calcula(Orcamento orcamento) {
return orcamento.getValor()*0.06 + calculoDoOutroImposto(orcamento);
}
}
public class TestaImpostoComplexo {
public static void main(String[] args) {
Imposto iss = new ISS(new ICMS(new ICCC()));
Orcamento orcamento = new Orcamento(500);
double valor = iss.calcula(orcamento);
System.out.println(valor);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment