Created
July 4, 2018 19:38
-
-
Save alexandreaquiles/b5abdefd8f440815f1b13e0f9041e806 to your computer and use it in GitHub Desktop.
Solução sugerida para exercício de Refatoração do PM-87.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class CalculadoraDePrecos { | |
public static BigDecimal calcula(Sessao sessao, Integer quantidade) { | |
return sessao.calcula(quantidade); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Entity | |
public class Sessao { | |
//outros métodos... | |
public BigDecimal calcula(Integer quantidade) { | |
BigDecimal preco = espetaculo.getTipo().calcula(this, quantidade); | |
return preco.multiply(BigDecimal.valueOf(quantidade)); | |
} | |
public double porcentagemDeIngressosFaltando() { | |
return (totalIngressos - ingressosReservados) / totalIngressos.doubleValue(); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public enum TipoDeEspetaculo { | |
CINEMA(0.05, 0.1, 0.0), | |
SHOW(0.05, 0.1, 0.0), | |
TEATRO(0.0, 0.0, 0.0), | |
BALLET(0.5, 0.2, 0.1), | |
ORQUESTRA(0.5, 0.2, 0.1); | |
private double acrescimoFaltantes; | |
private double porcentagemFaltantes; | |
private double acrescimoDuracao; | |
private TipoDeEspetaculo(double porcentagemFaltantes, double acrescimoFaltantes, double acrescimoDuracao) { | |
this.porcentagemFaltantes = porcentagemFaltantes; | |
this.acrescimoFaltantes = acrescimoFaltantes; | |
this.acrescimoDuracao = acrescimoDuracao; | |
} | |
public BigDecimal calcula(Sessao sessao, Integer quantidade) { | |
BigDecimal preco = sessao.getPreco(); | |
if (acrescimoFaltantes > 0 && sessao.porcentagemDeIngressosFaltando() <= porcentagemFaltantes) { | |
preco = preco.add(preco.multiply(BigDecimal.valueOf(acrescimoFaltantes))); | |
} | |
if(acrescimoDuracao > 0 && sessao.getDuracaoEmMinutos() > 60){ | |
preco = preco.add(sessao.getPreco().multiply(BigDecimal.valueOf(acrescimoDuracao))); | |
} | |
return preco; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment