中文字幕在线观看,亚洲а∨天堂久久精品9966,亚洲成a人片在线观看你懂的,亚洲av成人片无码网站,亚洲国产精品无码久久久五月天

Java 等額本金等額本息工具類

2018-07-20    來(lái)源:open-open

容器云強(qiáng)勢(shì)上線!快速搭建集群,上萬(wàn)Linux鏡像隨意使用
等額本息:
/**
 * Description:等額本息工具類
 * Copyright: Copyright (corporation)2015
 * Company: Corporation
 * @author: 凱文加內(nèi)特
 * @version: 1.0
 * Created at: 2015年11月30日 下午3:45:46
 * Modification History:
 * Modified by : 
 */
 
package com.utils;
 
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;
 
/**
 * 等額本息還款,也稱定期付息,即借款人每月按相等的金額償還貸款本息,其中每月貸款利息按月初剩余貸款本金計(jì)算并逐月結(jié)清。把按揭貸款的本金總額與利息總額相加,
 * 然后平均分?jǐn)偟竭款期限的每個(gè)月中。作為還款人,每個(gè)月還給銀行固定金額,但每月還款額中的本金比重逐月遞增、利息比重逐月遞減。
 */
 
public class AverageCapitalPlusInterestUtils {
 
    /**
     * 等額本息計(jì)算獲取還款方式為等額本息的每月償還本金和利息
     * 
     * 公式:每月償還本息=〔貸款本金×月利率×(1+月利率)^還款月數(shù)〕÷〔(1+月利率)^還款月數(shù)-1〕
     * 
     * @param invest
     *            總借款額(貸款本金)
     * @param yearRate
     *            年利率
     * @param month
     *            還款總月數(shù)
     * @return 每月償還本金和利息,不四舍五入,直接截取小數(shù)點(diǎn)最后兩位
     */
    public static double getPerMonthPrincipalInterest(double invest, double yearRate, int totalmonth) {
        double monthRate = yearRate / 12;
        BigDecimal monthIncome = new BigDecimal(invest)
                .multiply(new BigDecimal(monthRate * Math.pow(1 + monthRate, totalmonth)))
                .divide(new BigDecimal(Math.pow(1 + monthRate, totalmonth) - 1), 2, BigDecimal.ROUND_DOWN);
        return monthIncome.doubleValue();
    }
 
    /**
     * 等額本息計(jì)算獲取還款方式為等額本息的每月償還利息
     * 
     * 公式:每月償還利息=貸款本金×月利率×〔(1+月利率)^還款月數(shù)-(1+月利率)^(還款月序號(hào)-1)〕÷〔(1+月利率)^還款月數(shù)-1〕
     * @param invest
     *            總借款額(貸款本金)
     * @param yearRate
     *            年利率
     * @param month
     *            還款總月數(shù)
     * @return 每月償還利息
     */
    public static Map<Integer, BigDecimal> getPerMonthInterest(double invest, double yearRate, int totalmonth) {
        Map<Integer, BigDecimal> map = new HashMap<Integer, BigDecimal>();
        double monthRate = yearRate/12;
        BigDecimal monthInterest;
        for (int i = 1; i < totalmonth + 1; i++) {
            BigDecimal multiply = new BigDecimal(invest).multiply(new BigDecimal(monthRate));
            BigDecimal sub  = new BigDecimal(Math.pow(1 + monthRate, totalmonth)).subtract(new BigDecimal(Math.pow(1 + monthRate, i-1)));
            monthInterest = multiply.multiply(sub).divide(new BigDecimal(Math.pow(1 + monthRate, totalmonth) - 1), 6, BigDecimal.ROUND_DOWN);
            monthInterest = monthInterest.setScale(2, BigDecimal.ROUND_DOWN);
            map.put(i, monthInterest);
        }
        return map;
    }
 
    /**
     * 等額本息計(jì)算獲取還款方式為等額本息的每月償還本金
     * 
     * @param invest
     *            總借款額(貸款本金)
     * @param yearRate
     *            年利率
     * @param month
     *            還款總月數(shù)
     * @return 每月償還本金
     */
    public static Map<Integer, BigDecimal> getPerMonthPrincipal(double invest, double yearRate, int totalmonth) {
        double monthRate = yearRate / 12;
        BigDecimal monthIncome = new BigDecimal(invest)
                .multiply(new BigDecimal(monthRate * Math.pow(1 + monthRate, totalmonth)))
                .divide(new BigDecimal(Math.pow(1 + monthRate, totalmonth) - 1), 2, BigDecimal.ROUND_DOWN);
        Map<Integer, BigDecimal> mapInterest = getPerMonthInterest(invest, yearRate, totalmonth);
        Map<Integer, BigDecimal> mapPrincipal = new HashMap<Integer, BigDecimal>();
 
        for (Map.Entry<Integer, BigDecimal> entry : mapInterest.entrySet()) {
            mapPrincipal.put(entry.getKey(), monthIncome.subtract(entry.getValue()));
        }
        return mapPrincipal;
    }
 
    /**
     * 等額本息計(jì)算獲取還款方式為等額本息的總利息
     * 
     * @param invest
     *            總借款額(貸款本金)
     * @param yearRate
     *            年利率
     * @param month
     *            還款總月數(shù)
     * @return 總利息
     */
    public static double getInterestCount(double invest, double yearRate, int totalmonth) {
        BigDecimal count = new BigDecimal(0);
        Map<Integer, BigDecimal> mapInterest = getPerMonthInterest(invest, yearRate, totalmonth);
 
        for (Map.Entry<Integer, BigDecimal> entry : mapInterest.entrySet()) {
            count = count.add(entry.getValue());
        }
        return count.doubleValue();
    }
 
    /**
     * 應(yīng)還本金總和
     * @param invest
     *            總借款額(貸款本金)
     * @param yearRate
     *            年利率
     * @param month
     *            還款總月數(shù)
     * @return 應(yīng)還本金總和
     */
    public static double getPrincipalInterestCount(double invest, double yearRate, int totalmonth) {
        double monthRate = yearRate / 12;
        BigDecimal perMonthInterest = new BigDecimal(invest)
                .multiply(new BigDecimal(monthRate * Math.pow(1 + monthRate, totalmonth)))
                .divide(new BigDecimal(Math.pow(1 + monthRate, totalmonth) - 1), 2, BigDecimal.ROUND_DOWN);
        BigDecimal count = perMonthInterest.multiply(new BigDecimal(totalmonth));
        count = count.setScale(2, BigDecimal.ROUND_DOWN);
        return count.doubleValue();
    }
 
    /**
     * @param args
     */
    public static void main(String[] args) {
        double invest = 20000; // 本金
        int month = 12;
        double yearRate = 0.15; // 年利率
        double perMonthPrincipalInterest = getPerMonthPrincipalInterest(invest, yearRate, month);
        System.out.println("等額本息---每月還款本息:" + perMonthPrincipalInterest);
        Map<Integer, BigDecimal> mapInterest = getPerMonthInterest(invest, yearRate, month);
        System.out.println("等額本息---每月還款利息:" + mapInterest);
        Map<Integer, BigDecimal> mapPrincipal = getPerMonthPrincipal(invest, yearRate, month);
        System.out.println("等額本息---每月還款本金:" + mapPrincipal);
        double count = getInterestCount(invest, yearRate, month);
        System.out.println("等額本息---總利息:" + count);
        double principalInterestCount = getPrincipalInterestCount(invest, yearRate, month);
        System.out.println("等額本息---應(yīng)還本息總和:" + principalInterestCount);
    }
}

等額本金:

/**
 * Description:等額本金工具類
 * Copyright: Copyright (Corporation)2015
 * Company: Corporation
 * @author: 凱文加內(nèi)特
 * @version: 1.0
 * Created at: 2015年12月1日 上午8:38:23
 * Modification History:
 * Modified by : 
 */
 
package com.utils;
 
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;
 
/**
 * 等額本金是指一種貸款的還款方式,是在還款期內(nèi)把貸款數(shù)總額等分,每月償還同等數(shù)額的本金和剩余貸款在該月所產(chǎn)生的利息,這樣由于每月的還款本金額固定,
 * 而利息越來(lái)越少,借款人起初還款壓力較大,但是隨時(shí)間的推移每月還款數(shù)也越來(lái)越少。
 */
public class AverageCapitalUtils {
 
    /**
     * 等額本金計(jì)算獲取還款方式為等額本金的每月償還本金和利息
     * 
     * 公式:每月償還本金=(貸款本金÷還款月數(shù))+(貸款本金-已歸還本金累計(jì)額)×月利率
     * 
     * @param invest
     *            總借款額(貸款本金)
     * @param yearRate
     *            年利率
     * @param month
     *            還款總月數(shù)
     * @return 每月償還本金和利息,不四舍五入,直接截取小數(shù)點(diǎn)最后兩位
     */
    public static Map<Integer, Double> getPerMonthPrincipalInterest(double invest, double yearRate, int totalMonth) {
        Map<Integer, Double> map = new HashMap<Integer, Double>();
        // 每月本金
        double monthPri = getPerMonthPrincipal(invest, totalMonth);
        // 獲取月利率
        double monthRate = yearRate / 12;
        monthRate = new BigDecimal(monthRate).setScale(6, BigDecimal.ROUND_DOWN).doubleValue();
        for (int i = 1; i <= totalMonth; i++) {
            double monthRes = monthPri + (invest - monthPri * (i - 1)) * monthRate;
            monthRes = new BigDecimal(monthRes).setScale(2, BigDecimal.ROUND_DOWN).doubleValue();
            map.put(i, monthRes);
        }
        return map;
    }
 
    /**
     * 等額本金計(jì)算獲取還款方式為等額本金的每月償還利息
     * 
     * 公式:每月應(yīng)還利息=剩余本金×月利率=(貸款本金-已歸還本金累計(jì)額)×月利率
     * 
     * @param invest
     *            總借款額(貸款本金)
     * @param yearRate
     *            年利率
     * @param month
     *            還款總月數(shù)
     * @return 每月償還利息
     */
    public static Map<Integer, Double> getPerMonthInterest(double invest, double yearRate, int totalMonth) {
        Map<Integer, Double> inMap = new HashMap<Integer, Double>();
        double principal = getPerMonthPrincipal(invest, totalMonth);
        Map<Integer, Double> map = getPerMonthPrincipalInterest(invest, yearRate, totalMonth);
        for (Map.Entry<Integer, Double> entry : map.entrySet()) {
            BigDecimal principalBigDecimal = new BigDecimal(principal);
            BigDecimal principalInterestBigDecimal = new BigDecimal(entry.getValue());
            BigDecimal interestBigDecimal = principalInterestBigDecimal.subtract(principalBigDecimal);
            interestBigDecimal = interestBigDecimal.setScale(2, BigDecimal.ROUND_DOWN);
            inMap.put(entry.getKey(), interestBigDecimal.doubleValue());
        }
        return inMap;
    }
 
    /**
     * 等額本金計(jì)算獲取還款方式為等額本金的每月償還本金
     * 
     * 公式:每月應(yīng)還本金=貸款本金÷還款月數(shù)
     * 
     * @param invest
     *            總借款額(貸款本金)
     * @param yearRate
     *            年利率
     * @param month
     *            還款總月數(shù)
     * @return 每月償還本金
     */
    public static double getPerMonthPrincipal(double invest, int totalMonth) {
        BigDecimal monthIncome = new BigDecimal(invest).divide(new BigDecimal(totalMonth), 2, BigDecimal.ROUND_DOWN);
        return monthIncome.doubleValue();
    }
 
    /**
     * 等額本金計(jì)算獲取還款方式為等額本金的總利息
     * 
     * @param invest
     *            總借款額(貸款本金)
     * @param yearRate
     *            年利率
     * @param month
     *            還款總月數(shù)
     * @return 總利息
     */
    public static double getInterestCount(double invest, double yearRate, int totalMonth) {
        BigDecimal count = new BigDecimal(0);
        Map<Integer, Double> mapInterest = getPerMonthInterest(invest, yearRate, totalMonth);
 
        for (Map.Entry<Integer, Double> entry : mapInterest.entrySet()) {
            count = count.add(new BigDecimal(entry.getValue()));
        }
        return count.doubleValue();
    }
 
    /**
     * @param args
     */
    public static void main(String[] args) {
        double invest = 10000; // 本金
        int month = 12;
        double yearRate = 0.15; // 年利率
        Map<Integer, Double> getPerMonthPrincipalInterest = getPerMonthPrincipalInterest(invest, yearRate, month);
        System.out.println("等額本金---每月本息:" + getPerMonthPrincipalInterest);
        double benjin = getPerMonthPrincipal(invest, month);
        System.out.println("等額本金---每月本金:" + benjin);
        Map<Integer, Double> mapInterest = getPerMonthInterest(invest, yearRate, month);
        System.out.println("等額本金---每月利息:" + mapInterest);
 
        double count = getInterestCount(invest, yearRate, month);
        System.out.println("等額本金---總利息:" + count);
    }
}

標(biāo)簽:

版權(quán)申明:本站文章部分自網(wǎng)絡(luò),如有侵權(quán),請(qǐng)聯(lián)系:west999com@outlook.com
特別注意:本站所有轉(zhuǎn)載文章言論不代表本站觀點(diǎn)!
本站所提供的圖片等素材,版權(quán)歸原作者所有,如需使用,請(qǐng)與原作者聯(lián)系。

上一篇:PHP 單例模式實(shí)現(xiàn)

下一篇:Android 圖片選擇器