贷款利息计算

复制代码
package test;

import java.net.ServerSocket;

public class Profit {
    public Profit() {
    }

    static int loadYears = 25;

    public static void main(String[] args) {
        //gongjijin: 0.0325d
        //shang dai: 0.0515d
        
         dengBenJin(175, 0.0515d*0.88);
        double sum=0;
//                sum= dengE(120, 0.0325d);
//        sum+=dengE(55,0.0515d*0.88);
//        System.out.println("sum:"+sum);
    }

    static double dengE(double load, double loadInterest) {

        // final value
        load*=10000  ;
        double monthProfit = loadInterest / 12;
        double monthPay = load * monthProfit * Math.pow(1 + monthProfit, loadYears * 12) / (Math.pow(1 + monthProfit, loadYears * 12) - 1); 
        int startMonth = 0;// the month started to pay back. 0 means start from
                            // Jan.
        int startYear = 14; // the year start to pay back. 14 means start from
                            // 2014.

        double sum = 0;
        double remainLoad = load;
        for (int i = startMonth; i < loadYears * 12 + startMonth; i++) {
            double interest = remainLoad * monthProfit;
            double monthBenjin = (monthPay - interest);
            remainLoad -= monthBenjin;

            sum += monthPay;
            int theMonth = i % 12;
            int theYear = i / 12;

            if (theMonth == 0)
                System.out.println(2000 + (theYear + startYear) + "年");
            // System.out.println("\t" + (theMonth + 1) + "月\t\t" + monthPay +
            // "元\t" + "\t 本金:" +monthBenjin + "\t 利息:" + interest);
            System.out.println("\t" + (theMonth + 1) + "月\t\t" + convert(monthPay) + "元\t" + "\t 本金:" + convert(monthBenjin) + "\t 利息:"
                    + convert(interest));

        }
        System.out.println(" 总共付款 " + "\t\t" + convert(sum) + "元\n利息:\t\t " + convert(sum - load) + "元");
//        System.out.println(" 总共付款" + "\t\t" + monthPay*12*years + "元\n利息:\t\t " + (monthPay*12*years - base) + "元");
        return sum - load;
    }

    private static double dengBenJin(double load, double loadInterest) {

        // final value
        load*=10000  ;
        double monthProfit = loadInterest / 12;
        double monthBenjin = load / (loadYears * 12);
        int startMonth = 0;// the month started to pay back. 0 means start from
                            // Jan.
        int startYear = 14; // the year start to pay back. 14 means start from
                            // 2014.

        double sum = 0;
        for (int i = startMonth; i < loadYears * 12 + startMonth; i++) {
            double interest = (load - monthBenjin * (i - startMonth)) * monthProfit;
            double monthPay = monthBenjin + interest;
            sum += monthPay;
            int theMonth = i % 12;
            int theYear = i / 12;

            if (theMonth == 0)
                System.out.println(2000 + (theYear + startYear) + "年");
            System.out.println("\t" + (theMonth + 1) + "月\t\t" + convert(monthPay) + "元\t" + "\t 本金:" + convert(monthBenjin) + "\t 利息:" + convert(interest));

        }
        System.out.println(" 总共付款 " + "\t\t" + sum + "元\n利息:\t\t " + (sum - load) + "元");
        return sum - load;
    }

    static double convert(double value) {
        long l1 = Math.round(value * 100); // 四舍五入
        double ret = l1 / 100.0; // 注意:使用 100.0 而不是 100
        return ret;
    }

}
复制代码

 

posted @   Bigben  阅读(192)  评论(0编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
点击右上角即可分享
微信分享提示