住房公积金 计算器-java方法

计算了一下房贷压力,以全额公积金贷款为例,贷款四十万,等额本金方式还款,房贷利率为2.85%,基本情况就是如下:
在这里插入图片描述

在这里插入图片描述
还款总额达到

提前还款的好处

按三十年计算,如果第一年借用亲朋好友的钱(不出利息)。

打个比方,借了亲人五万,借亲人的钱一年或者两年内还清。那么把这五万放在房贷中,三十年的公积金利息就少了4万员还提前还了四年。
在这里插入图片描述571474.77 - 532643.52

每年多还款的好处

如果每年除了(月供)按月还款,还额外提前还款4万,那么总利息将近少十万。而且提前到七年就可以还款结束。
446547.35 - 437379.86
在这里插入图片描述

代码如下:

public static void main(String[] args) {
        calc();
    }
    public static void calc(){
        Integer monthCount =360;
        // 贷款金额
        BigDecimal totalLoan = new BigDecimal(400000);
        // 每年提前还的金额
        BigDecimal yearMoney = new BigDecimal(0);
        // 利车
        BigDecimal yearRate = new BigDecimal( 0.0285);
        // 月利车
        BigDecimal monthlyRate = yearRate.divide(new BigDecimal(12), 7,RoundingMode.HALF_UP);
        // 每月应还本金
        BigDecimal monthlyPrincipal = totalLoan.divide(new BigDecimal(monthCount), 2, RoundingMode.HALF_UP);
        BigDecimal rateTotal = new BigDecimal( 0);
        Boolean isFirst = true;
        for (int i = 1; i <= monthCount; i++) {
            if (totalLoan.compareTo(BigDecimal.ZERO) < 0) {
            	System.out.println("多余还款:"+totalLoan);
                // 增加多余的还款金额
                rateTotal = rateTotal.add(totalLoan);
                
                break;
            }

            if (i % 12 == 0) {
                if(totalLoan.compareTo(yearMoney) < 0){
                    rateTotal = rateTotal.add(totalLoan);
                    break;
                }
                totalLoan = totalLoan.subtract(yearMoney);
                rateTotal = rateTotal.add(yearMoney);
                if(isFirst){
                    totalLoan = totalLoan.subtract(new BigDecimal(50000));
                    rateTotal = rateTotal.add(new BigDecimal(50000));
                    isFirst = false;
                }
            }
            if (totalLoan.compareTo(monthlyPrincipal) < 0) {
                System.out.println("还款完成");
                break;
            }
            // 当月利息=剩余本金*月利率
            BigDecimal currentInterest = totalLoan.multiply(monthlyRate).setScale(2, RoundingMode.HALF_UP);
            // 当月总还款额=每月应还本金+当月利息
            BigDecimal monthlyPayment = monthlyPrincipal.add(currentInterest);
            // 每月剩余本金
            totalLoan = totalLoan.subtract(monthlyPrincipal);
            rateTotal = rateTotal.add(monthlyPayment);
            System.out.println("第" + i + "月,应还本金:" + monthlyPrincipal + ",利息:" + currentInterest + ",还款总额:" + monthlyPayment +",剩余本金:" + totalLoan);
        }
        System.out.println("还款总额:" + rateTotal);
    }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值