private static void makeChange(final int values[], final int types, int total, final int coinUsed[], final int coinTrack[]) {
        coinUsed[0] = 0;
        coinTrack[0] = 0;

        for (int i = 1; i <= total; i++) {
            int minCoin = i;
            int coin = 0;
            // try each type of coin to see which one give us the min number of coins
            // use the saved value of the previous operation
            for (int j = 0; j < types; j++) {
                if (values[j] <= i) {
                    if (coinUsed[i - values[j]] + 1 < minCoin) {
                        minCoin = coinUsed[i - values[j]] + 1;
                        coin = values[j];
                    }
                }
            }
            coinUsed[i] = minCoin;
            // get the coin used
            // this array records all the j value we chose(which would make the min number) for each amount from 1 to
            // total
            coinTrack[i] = coin;
        }

        System.out.println("the min number of coins to get " + total + " dollars is " + coinUsed[total]);

        // print out the coins used(optional; use an extra array)
        while (total > 0) {
            System.out.println(coinTrack[total]);
            total -= coinTrack[total];
        }
    }