3
I need to improve a part of the code.
My problem is it’s too repetitive if
and else
, the bad news is that I will have more repetitive things on account that are different games.
I can improve this part of the code by something more readable or even smaller?
public Double valuesGames(String game){
if (game.equals(constantes.getGameDiadeSorte())){
//Valores referente a Dia de Sorte
if (getNumbersBalls().size() <= 7){
value = constantes.getAmountDiaDeSorte();
}else if (getNumbersBalls().size() == 8){
value = constantes.getAmountDiaDeSorte() + 3;
}else if (getNumbersBalls().size() == 9){
value = constantes.getAmountDiaDeSorte() + 4;
}else if (getNumbersBalls().size() == 10){
value = constantes.getAmountDiaDeSorte() + 5;
}else if (getNumbersBalls().size() == 11){
value = constantes.getAmountDiaDeSorte() + 6;
}else if (getNumbersBalls().size() == 12){
value = constantes.getAmountDiaDeSorte() + 7;
}else if (getNumbersBalls().size() == 13){
value = constantes.getAmountDiaDeSorte() + 10;
}else if (getNumbersBalls().size() == 14){
value = constantes.getAmountDiaDeSorte() + 11;
}else if (getNumbersBalls().size() == 15){
value = constantes.getAmountDiaDeSorte() + 15;
}
} else if (game.equals(constantes.getGameQuina())){
//Valores referente a QUINA
if (getNumbersBalls().size() <= 5){
value = constantes.getAmountQuina();
}else if (getNumbersBalls().size() == 6){
value = constantes.getAmountQuina() * 3;
}else if (getNumbersBalls().size() == 7){
value = constantes.getAmountQuina() * 4;
}else if (getNumbersBalls().size() == 8){
value = constantes.getAmountQuina() * 5;
}else if (getNumbersBalls().size() == 9){
value = constantes.getAmountQuina() * 6;
}else if (getNumbersBalls().size() == 10){
value = constantes.getAmountQuina() * 7;
}else if (getNumbersBalls().size() == 11){
value = constantes.getAmountQuina() * 8;
}else if (getNumbersBalls().size() == 12){
value = constantes.getAmountQuina() * 9;
}else if (getNumbersBalls().size() == 13){
value = constantes.getAmountQuina() * 10;
}else if (getNumbersBalls().size() == 14){
value = constantes.getAmountQuina() * 11;
}else if (getNumbersBalls().size() == 15){
value = constantes.getAmountQuina() * 12;
}
}else if (game.equals(constantes.getGameMega())){
//Valores referente a MEGA-SENA
if (getNumbersBalls().size() <= 6){
value = constantes.getAmountMega();
}else if (getNumbersBalls().size() == 7){
value = constantes.getAmountMega() * 3;
}else if (getNumbersBalls().size() == 8){
value = constantes.getAmountMega() * 4;
}else if (getNumbersBalls().size() == 9){
value = constantes.getAmountMega() * 5;
}else if (getNumbersBalls().size() == 10){
value = constantes.getAmountMega() * 6;
}else if (getNumbersBalls().size() == 11){
value = constantes.getAmountMega() * 7;
}else if (getNumbersBalls().size() == 12){
value = constantes.getAmountMega() * 8;
}else if (getNumbersBalls().size() == 13){
value = constantes.getAmountMega() * 9;
}else if (getNumbersBalls().size() == 14){
value = constantes.getAmountMega() * 10;
}else if (getNumbersBalls().size() == 15){
value = constantes.getAmountMega() * 11;
}
}
return value;
}
Yes and much, both in structure and logic.
– Leandro Angelo
you can give me a light on how to make this change ?
– Edi
One of the things you can do is call these getAmount functions only once and then treat the result of it. Same thing p get number Balls function
– lvr7
@Edi you can also replace the
else ifs
by aswitch case
.– William
@William this would not lessen the repetition.
– Maniero
A game could not be a base class where each type of game implements it and has its own 'valuesGames()'? This would decrease the code within a single function. There would be 3 classes: one for Lucky Day, another Quina and another Mega sena
– Kevin Kouketsu