Gente tem alguma forma de testar o valor do salário e a idade da pessoa sem usar tantos ifss, como fiz abaixo. É que o prof, pediu para modularizar mais e utilizar menos if. Desenvolvi como está abaixo, mas tem muito if, acho que ele vai reclamar
, alguém tem alguma sugestão?
Tipo assim:
public double getClassificacaoEtaria( char sexo )
{
double[] limitePorcentagem = null;
int[] limiteIdade = null;
if (sexo == 'F')
limiteIdade = IDADE_MULHER;
else if( sexo == 'M' )
limiteIdade = IDADE_HOMEM ;
if( sexo == 'M')
{
if( idadeUI <= 35 )
{
if ( salarioUI <= 5000 )
limitePorcentagem = PORCENTAGEM_EMPRESTIMO_HOMEM_SALARIO_MENOR;
else if ( salarioUI > 5000 && salarioUI <= 10000 )
limitePorcentagem = PORCENTAGEM_EMPRESTIMO_HOMEM_SALARIO_MAIOR;
}
else if( idadeUI >= 36 && idadeUI <= 45 )
{
if( salarioUI <= 6000)
limitePorcentagem = PORCENTAGEM_EMPRESTIMO_HOMEM_SALARIO_MENOR;
else if( salarioUI > 6000 && salarioUI <= 10000 )
limitePorcentagem = PORCENTAGEM_EMPRESTIMO_HOMEM_SALARIO_MAIOR;
}
else if( idadeUI >= 46 && idadeUI <= 56 )
{
if( salarioUI <= 10000 )
limitePorcentagem = PORCENTAGEM_EMPRESTIMO_HOMEM_SALARIO_MAIOR;
}
}
else if( salarioUI <= 10000 )
{
limitePorcentagem = PORCENTAGEM_EMPRESTIMO_MULHER;
}
return getCalculaEmprestimo( limiteIdade, limitePorcentagem );
}
public double getCalculaEmprestimo( int[] idade, double[] porcentagem )
{
try
{
double valorEmprestimo = 0.0;
if ( idadeUI < MENOR_IDADE )
{
return 0;
}
else
{
for( int i = 0; i < idade.length; i++ )
{
if( idadeUI <= idade[i] )
{
valorEmprestimo = salarioUI * porcentagem[i];
return valorEmprestimo ;
}
}
}
}
catch( Exception e)
{
e.getMessage();
}
return 0;
}