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;
    }

}

 

版权声明:本文为bigben0123原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/bigben0123/p/4901549.html