import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.HashMap;
import java.util.Map;/*** 等额本息*/
public class EqualPrincipalInterestUtil {/*** 每期本金+利息* 公式:每月偿还本息=〔贷款本金×月利率×(1+月利率)^还款月数〕÷〔(1+月利率)^还款月数-1)* @param invest*            本金* @param periodRate*            每期利率* @param periodMonthNum*            期数* @return*/public static double getPerPeriodPrincipalInterest(double invest, double periodRate, int periodMonthNum) {BigDecimal monthIncome = new BigDecimal(invest).multiply(new BigDecimal(periodRate * Math.pow(1 + periodRate, periodMonthNum))).divide(new BigDecimal(Math.pow(1 + periodRate, periodMonthNum) - 1), 4, BigDecimal.ROUND_HALF_UP);return monthIncome.doubleValue();}/*** 每期利息* 公式:每月偿还利息=贷款本金×月利率×〔(1+月利率)^还款月数-(1+月利率)^(还款月序号-1)〕÷〔(1+月利率)^还款月数-1〕* @param invest*            本金* @param periodRate*            每期利率* @param periodMonthNum*            期数* @return*/public static Map<Integer, BigDecimal> getPerPeriodInterest(double invest, double periodRate, int periodMonthNum) {Map<Integer, BigDecimal> map = new HashMap<Integer, BigDecimal>();BigDecimal periodInterest;for (int i = 1; i < periodMonthNum + 1; i++) {BigDecimal multiply = new BigDecimal(invest).multiply(new BigDecimal(periodRate));BigDecimal sub = new BigDecimal(Math.pow(1 + periodRate, periodMonthNum)).subtract(new BigDecimal(Math.pow(1 + periodRate, i - 1)));periodInterest = multiply.multiply(sub).divide(new BigDecimal(Math.pow(1 + periodRate, periodMonthNum) - 1),6, BigDecimal.ROUND_HALF_UP);periodInterest = periodInterest.setScale(4, BigDecimal.ROUND_HALF_UP);map.put(i, periodInterest);}return map;}/*** 每期还款本金* * @param invest*            本金* @param periodRate*            每期利率* @param periodNum*            期数* @return*/public static Map<Integer, BigDecimal> getPerPeriodPrincipal(double invest, double periodRate, int periodNum) {BigDecimal monthIncome = new BigDecimal(invest).multiply(new BigDecimal(periodRate * Math.pow(1 + periodRate, periodNum))).divide(new BigDecimal(Math.pow(1 + periodRate, periodNum) - 1), 4, BigDecimal.ROUND_HALF_UP);Map<Integer, BigDecimal> mapInterest = getPerPeriodInterest(invest, periodRate, periodNum);Map<Integer, BigDecimal> mapPrincipal = new HashMap<Integer, BigDecimal>();for (Map.Entry<Integer, BigDecimal> entry : mapInterest.entrySet()) {mapPrincipal.put(entry.getKey(), monthIncome.subtract(entry.getValue()));}return mapPrincipal;}/*** 总利息* * @param invest*            本金* @param periodRate*            每期利率* @param periodNum*            期数* @return*/public static double getInterestCount(double invest, double periodRate, int periodNum) {BigDecimal count = new BigDecimal(0);Map<Integer, BigDecimal> mapInterest = getPerPeriodInterest(invest, periodRate, periodNum);for (Map.Entry<Integer, BigDecimal> entry : mapInterest.entrySet()) {count = count.add(entry.getValue());}return count.doubleValue();}/*** 本息总和* * @param invest*            本金* @param periodRate*            每期利率* @param periodNum*            期数* @return*/public static double getPrincipalInterestCount(double invest, double periodRate, int periodNum) {BigDecimal perMonthInterest = new BigDecimal(invest);Map<Integer, BigDecimal> mapInterest = getPerPeriodInterest(invest, periodRate, periodNum);for (Map.Entry<Integer, BigDecimal> entry : mapInterest.entrySet()) {perMonthInterest = perMonthInterest.add(entry.getValue());}return perMonthInterest.doubleValue();}/*** 每期还款日期* @param start_date*              起租日* @param perPeriodMonthNum*                 每期月数* @param periodNum*                期数* @return*/public static Map<Integer, String> getRepaymentDate(String start_date, int perPeriodMonthNum, int periodNum) {Map<Integer, String> periodRepaymentDate = new HashMap<Integer, String>();String nextRepaymentDate = start_date;periodRepaymentDate.put(1, nextRepaymentDate);for (int i = 2; i < periodNum + 1; i++) {nextRepaymentDate = getMonthAdd(perPeriodMonthNum, nextRepaymentDate, "yyyyMMdd");periodRepaymentDate.put(i, nextRepaymentDate);}return periodRepaymentDate;}/*** 功能描述:返回指定日期加上多少月之后的时间<BR>* @param from   yyyyMMdd* @param day* @param formatStr* @return*/public static String getMonthAdd(int day,String from,String formatStr){SimpleDateFormat sdf=new SimpleDateFormat(formatStr);Calendar calendar = Calendar.getInstance();try {calendar.setTime(sdf.parse(from));} catch (Exception e) {e.printStackTrace();}calendar.add(Calendar.MONTH, day);String date = sdf.format(calendar.getTime());return date;}public static void main(String[] args) {  double invest = 10000; // 本金  int periodNum = 4;double periodRate = 0.12/3; // 年利率  System.out.println("等额本息---本金:" + invest);  double perMonthPrincipalInterest = getPerPeriodPrincipalInterest(invest, periodRate, periodNum);  System.out.println("等额本息---每期还款本息:" + perMonthPrincipalInterest);  Map<Integer, BigDecimal> mapInterest = getPerPeriodInterest(invest, periodRate, periodNum);  System.out.println("等额本息---每期还款利息:" + mapInterest);  Map<Integer, BigDecimal> mapPrincipal = getPerPeriodPrincipal(invest, periodRate, periodNum);  System.out.println("等额本息---每期还款本金:" + mapPrincipal);  double count = getInterestCount(invest, periodRate, periodNum);  System.out.println("等额本息---总利息:" + count);  double principalInterestCount = getPrincipalInterestCount(invest, periodRate, periodNum);  System.out.println("等额本息---应还本息总和:" + principalInterestCount);  }
}

Java实现等额本息相关推荐

  1. Java之~ 等额本息,等额本金,组合贷

    一,等额本息工具类 import java.math.BigDecimal; import java.text.DecimalFormat; import java.util.HashMap; imp ...

  2. 等额本金,等额本息,随借随还,利随本清,按月付息到期还本,5种还款方式java计算方法

    等额本金,等额本息,随借随还,利随本清,按月付息到期还本,5种还款方式java计算方法 等额本息定义:本金逐月递增,利息逐月递减,月还款数不变. 等额本金定义:本金保持相同,利息逐月递减,月还款数递减 ...

  3. java 等额本金等额本息工具类

    2019独角兽企业重金招聘Python工程师标准>>> 等额本息: /*** Description:等额本息工具类* Copyright: Copyright (corporati ...

  4. 等额本息贷款 ——已知贷款本金、月还款额、贷款月数,反推贷款月利率、年利率-java实现

    等额本息 每月还款计算公式: 每月本息金额 = (本金×月利率×(1+月利率)^还款月数)÷ ((1+月利率)^还款月数-1)) 反转求出 月利率 月利率 如果根据上面公式反转是算不出来的. 下面给出 ...

  5. Java实现:房贷计算器 (关键词:公积金、首付、等额本息、等额本金)

    1 背景:房贷计算器 目前现有的网页 房贷计算器,多多少少有点不符合自己需求,因此根据房贷相关公式及 java编写一个贷款计算器现有代码,改写了符合自己要求的 房贷计算器 . 计算结果精度为小数点后2 ...

  6. 贷款计算器- 等额本金、等额本息工具类(Java版)

    /** * Description:等额本金工具类 * Copyright: Copyright (Corporation)2015 * Company: Corporation * @version ...

  7. Java Swing写简单计算器以及拓展贷款计算器(等额本息和等额本金计算可以单独拿出来用)

    1. 简单计算器 纯手写 package com.jisuanqi;import com.sun.xml.internal.ws.util.StringUtils;import javax.swing ...

  8. 等额本金、等额本息工具类(Java版)

    等额本息: /** * Description:等额本息工具类 * Copyright: Copyright (corporation)2015 * Company: Corporation * @a ...

  9. java 模拟贷款实现等额本息还款

    还是菜鸟的我,在学习完java面向对象的思想后编写了一个模拟贷款的程序!! 一.首先创建一个类用于给变量赋值和输出. 代码如下: public class Loan {private double m ...

最新文章

  1. 输入框中默认的值,判断是否输入内容
  2. python小游戏代码大全-python小游戏实现代码
  3. 使用 gperf 实现高效的 C/C++ 命令行处理
  4. SAP面向iOS设备推Cloud Platform SDK工具
  5. cf1555A. PizzaForces
  6. 前端学习(3268):js中this在类中的表现
  7. Linux内存管理:反向映射机制(匿名页,文件页和ksm页)
  8. 理解Dubbo的调用流程与Dubbo多协议解析
  9. linux 信号集 同步,linux信号集
  10. ERP九大流程图(图)
  11. C++求解一元二次方程
  12. python爬虫 获取学信网 学校与对应专业信息
  13. 生成树协议三姐妹:STP、RSTP 和 MSTP,附思科和华为双厂商命令示例
  14. SpringBoot JPA多对一 持久化是报错object references an unsaved transient instance - save the transient instanc
  15. 计算机打开查看方式默认是什么样,如何设置电脑文件夹默认查看方式
  16. 分布式事务seat对于sql语句的语法要求
  17. 小米盒子3增强版 android tv,小米盒子3增强版刷Android TV系统
  18. 最全的linux上git教程
  19. C语言 交替符号累加计算
  20. 【转】手机软件商店(wiki)

热门文章

  1. 那些常被忽略的 html 标签
  2. 硕士阶段学习情况汇总
  3. Java面试笔试经验技巧总结
  4. Java 基础 Collection集合
  5. 开学了,献给就读IT相关专业的本科新生们
  6. html5获取坐标高德,vue 单纯的获取经纬度 百度与高德 H5
  7. thinkserver t340 u盘安装centos 遇到的问题
  8. 时序分析 43 -- 时序数据转为空间数据 (二) 马尔可夫转换场
  9. 什么专业要学计算机思维导论,大学计算机:计算思维导论CAP
  10. 终于把泰山OFFICE的MAC本地库问题都解决了