I was reviewing today some code which gets as input a list of payments (paymentList) and a list of installments (installmentList) has to populate two other lists, respectively depositList and balanceList.Basically it calculates the sum of all payments from paymentList and fills depositList with the amount enough to let each specific installment be payed.If the sum of all payments is less then the total of installments it fills as many installments as it can and then sets the balanceList with the amount which is missing.To make this clearer this is the output:paymentList    : 1200, 1000, 400, installmentList: 1200, 1200, 1200, 900, depositList    : 1200, 1200, 200, 0, balanceList    : 0, 0, -1000, -1900, if I made a total of 3 payments for 2600$, and I had to pay 4 installments, I would be able to pay the first two completely (with balance 0) and the third only with 200$ still having to pay 1000$, and the last installment would be completely missed for a total debt of 1900$.Seems easy enough however the code which does it stinks to me, here is a simplified version:public class Payment{    public static void main(String[] args)    {        ArrayList<Integer> paymentList = new ArrayList<Integer>()        {            {                add(1200);                add(1000);                add(400);            }        };        ArrayList<Integer> installmentList = new ArrayList<Integer>()        {            {                add(1200);                add(1200);                add(1200);                add(900);            }        };        printArray(paymentList    , paymentList);        printArray(installmentList, installmentList);        ArrayList<Integer> depositList = new ArrayList();        ArrayList<Integer> balanceList = new ArrayList();        Integer settledTotalAmount = 0;        for (Integer i : paymentList)        {            settledTotalAmount += i;        }        for (Integer currentInstallmentAmount : installmentList)        {            Integer settledAmount = 0;            if (settledTotalAmount > 0)            {                int tmpAmount = settledTotalAmount - currentInstallmentAmount;                if (tmpAmount > 0)                {                    settledAmount = currentInstallmentAmount;                    settledTotalAmount = tmpAmount;                    balanceList.add(0);                }                else                {                    settledAmount = currentInstallmentAmount+(tmpAmount);                    settledTotalAmount = (currentInstallmentAmount-settledAmount)*-1;                    balanceList.add((currentInstallmentAmount-settledAmount)*-1);                }            }            else            {                settledAmount = 0;                int k = (settledTotalAmount * -1)+currentInstallmentAmount;                settledTotalAmount = k*-1;                balanceList.add(settledTotalAmount);            }            depositList.add(settledAmount);        }        printArray(depositList    , depositList);        printArray(balanceList    , balanceList);    }    public static void printArray(String name, ArrayList<Integer> array)    {        System.out.print(name + : );        for (Integer i : array)        {            System.out.print(i + , );        }        System.out.println();    }}in particular the series of if else switches seems redundant to me, is there something cleaner for the above (which seems to work for now)?The version above actually is a simplified version, the original one I have uses BigDecimal and is even messier than that.
Splitting payments in a number of installments
java