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;
        }
    
    }
  • 相关阅读:
    Exchange调整入站SMTP连接超时时间
    使用WSS和SOFS管理集群存储--Storage
    String构造方法和字符集编码转换
    系统类和数学操作类
    JavaSE——数据类型流、内存流、打印流
    JavaSE——装饰设计模式+简单加密解密工程
    JavaSE——装饰设计模式
    JavaSE——装饰流
    JavaSE —— IO
    JavaSE —— IO简介
  • 原文地址:https://www.cnblogs.com/bigben0123/p/4901549.html
Copyright © 2011-2022 走看看