zoukankan      html  css  js  c++  java
  • 贷款利息计算

    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("	" + (theMonth + 1) + "月		" + monthPay +
                // "元	" + "	 本金:" +monthBenjin + "	 利息:" + interest);
                System.out.println("	" + (theMonth + 1) + "月		" + convert(monthPay) + "元	" + "	 本金:" + convert(monthBenjin) + "	 利息:"
                        + convert(interest));
    
            }
            System.out.println(" 总共付款 " + "		" + convert(sum) + "元
    利息:		 " + convert(sum - load) + "元");
    //        System.out.println(" 总共付款" + "		" + monthPay*12*years + "元
    利息:		 " + (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("	" + (theMonth + 1) + "月		" + convert(monthPay) + "元	" + "	 本金:" + convert(monthBenjin) + "	 利息:" + convert(interest));
    
            }
            System.out.println(" 总共付款 " + "		" + sum + "元
    利息:		 " + (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;
        }
    
    }
  • 相关阅读:
    HelloCSS-Border
    开发你的第一个NCS(Zephyr)应用程序
    NanoPi R4S (RK3399) openssl speed 硬件加解密性能测试结果
    Flink-状态
    Flink-时间语义和Watermark
    Flink-Window
    Flink-运行时架构
    Flink-流处理wordcount
    Flink-批处理wordcount
    设计模式七大原则-合成复用原则
  • 原文地址:https://www.cnblogs.com/bigben0123/p/4901549.html
Copyright © 2011-2022 走看看