0
Hello, I am with a project of a consortium calculator that is showing error. It receives from the user the following data:
- Value of the consortium
- Amount of months
- % from the reserve fund
- % of the administrative fee
After that he calculates the value of the monthly installment.
My problem is this: If I put the amount of months 10 works if put 15 already gives error.
Follows the code:
BigDecimal cota = new BigDecimal(jTextField1.getText());
BigDecimal prazo = new BigDecimal(jTextField2.getText());
BigDecimal reserva = new BigDecimal(jTextField3.getText());
BigDecimal adm = new BigDecimal(jTextField4.getText());
DecimalFormat decimal = new DecimalFormat("0.##");
//Calculo Fundo Comum
BigDecimal pc = new BigDecimal("100");
BigDecimal percentualMensal = pc.divide(prazo);
BigDecimal parcelaMensal = percentualMensal.multiply(cota);
BigDecimal parcelaMensal1 = parcelaMensal.divide(pc);
//Calculo Taxa Administrativa
BigDecimal a1 = adm.divide(prazo);
BigDecimal parcelaAdm = a1.multiply(cota);
BigDecimal parcelaAdm1 = parcelaAdm.divide(pc);
//Calculo Fundo Reserva
BigDecimal r1 = reserva.divide(prazo);
BigDecimal parcelaReserva = cota.multiply(r1);
BigDecimal parcelaReserva1 = parcelaReserva.divide(pc);
BigDecimal calculo = parcelaMensal1.add(parcelaAdm1.add(parcelaReserva1));
String a = decimal.format(calculo);
jLabel5.setText("Valor: "+a);
But what’s the mistake?
– Samuel Fontebasso
pc.divide(prazo);
- And if the division gives a periodic tithe, what should it do? The way it is, it will giveArithmeticException
.– Victor Stafusa
With 10 it works because 10 is divisor 100. 15 is not divisor 100, so it will give this exception. You have to say what you want to do when the division gives a periodic tithe.
– Victor Stafusa