Calculate the residual of a total deferred value to installments and add it to a jtable?

0
  private void PLAN_DE_PAGO_CREDITO() {
    int cntCuotas = 14;
    int totalVrCredito = 1.400.000;
    DefaultTableModel tableModel = (DefaultTableModel) TB_PLAN_PAGO.getModel();
    for (int i = 1; i <= cntCuotas ; i++) {
        int valorCuota = totalVrCredito/cntCuotas;
        totalVrCredito = totalVrCredito - valorCuota;
       //            System.out.println("Letra No: "+i+" - 
          ValorCuota: $ "+valorCuota);

        System.out.println("Letra No: "+i+" - 
         ValorSaldoCuota: $ "+totalVrCredito);

     }

     }

hello good day, maybe not a very relevant issue and that should be placed here apologies if so. But I have already tried to do it on my own and it did not work for me and for that reason I came to you who can help me thank you very much.

    
asked by Jose Felix 30.03.2018 в 10:24
source

1 answer

1

Regards Jose Felix.

What happens is that you were recalculating the valorCuota within the for , and for this reason, each time it was recalculated, the valorCuota changes its value, and you want to keep the same value. What you can do is calculate once valorCuota before for (so you would not have to create another variable like saldoCuota (that you indicated in the comments):

public void PLAN_DE_PAGO_CREDITO() {
    int cntCuotas = 14;
    int totalVrCredito = 1400000;

    int valorCuota = totalVrCredito / cntCuotas; // se calcula el valorCuota una sola vez

    for (int i = 1; i <= cntCuotas; i++) {
        totalVrCredito = totalVrCredito - valorCuota; // solamente se resta ese valorCuota

        System.out.println("Letra No: " + i + " - ValorCuota: $ " + valorCuota);
        System.out.println("Letra No: " + i + " - ValorSaldoCuota: $ " + totalVrCredito);
    }
}
    
answered by 30.03.2018 / 19:03
source