Java实现等额本金
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.HashMap;
import java.util.Map;/*** 等额本金*/
public class EqualPrincipalUtil {/** * 计算获取还款方式为等额本金的每期偿还本金和利息 * * 公式:每期偿还本金=(贷款本金÷还款期数)+(贷款本金-已归还本金累计额)×期利率 * * @param invest * 总借款额(贷款本金) * @param periodRate * 年利率 * @param periodNum * 还款总期数 * @return 每期偿还本金和利息,四舍五入*/ public static Map<Integer, Double> getPerPeriodPrincipalInterest(double invest, double periodRate, int periodNum) { Map<Integer, Double> map = new HashMap<Integer, Double>(); // 每期本金 double period = getPerPeriodPrincipal(invest, periodNum); // 获取期利率 periodRate = new BigDecimal(periodRate).setScale(6, BigDecimal.ROUND_HALF_UP).doubleValue(); for (int i = 1; i <= periodNum; i++) { double monthRes = period + (invest - period * (i - 1)) * periodRate; monthRes = new BigDecimal(monthRes).setScale(4, BigDecimal.ROUND_HALF_UP).doubleValue(); map.put(i, monthRes); } return map; } /** * 等额本金计算获取还款方式为等额本金的每期偿还利息 * * 公式:每期应还利息=剩余本金×期利率=(贷款本金-已归还本金累计额)×期利率 * * @param invest * 总借款额(贷款本金) * @param periodRate * 年利率 * @param periodNum * 还款总期数 * @return 每期偿还利息 */ public static Map<Integer, BigDecimal> getPerPeriodInterest(double invest, double periodRate, int periodNum) { Map<Integer, BigDecimal> inMap = new HashMap<Integer, BigDecimal>(); double principal = getPerPeriodPrincipal(invest, periodNum); Map<Integer, Double> map = getPerPeriodPrincipalInterest(invest, periodRate, periodNum); for (Map.Entry<Integer, Double> entry : map.entrySet()) { BigDecimal principalBigDecimal = new BigDecimal(principal); BigDecimal principalInterestBigDecimal = new BigDecimal(entry.getValue()); BigDecimal interestBigDecimal = principalInterestBigDecimal.subtract(principalBigDecimal); interestBigDecimal = interestBigDecimal.setScale(4, BigDecimal.ROUND_HALF_UP); inMap.put(entry.getKey(), interestBigDecimal); } return inMap; } /** * 等额本金计算获取还款方式为等额本金的每期偿还本金 * * 公式:每期应还本金=贷款本金÷还款期数 * * @param invest * 总借款额(贷款本金) * @param periodNum* 还款总期数 * @return 每期偿还本金 */ public static double getPerPeriodPrincipal(double invest, int periodNum) { BigDecimal monthIncome = new BigDecimal(invest).divide(new BigDecimal(periodNum), 4, BigDecimal.ROUND_HALF_UP); return monthIncome.doubleValue(); } /** * 等额本金计算获取还款方式为等额本金的总利息 * * @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; // 年利率 Map<Integer, Double> getPerMonthPrincipalInterest = getPerPeriodPrincipalInterest(invest, periodRate, periodNum); System.out.println("等额本金---每期本息:" + getPerMonthPrincipalInterest); double benjin = getPerPeriodPrincipal(invest, periodNum); System.out.println("等额本金---每期本金:" + benjin); Map<Integer, BigDecimal> mapInterest = getPerPeriodInterest(invest, periodRate, periodNum); System.out.println("等额本金---每期利息:" + mapInterest); double count = getInterestCount(invest, periodRate, periodNum); System.out.println("等额本金---总利息:" + count); double principalInterestCount = getPrincipalInterestCount(invest,periodRate,periodNum);System.out.println("等额本金---本息:" + principalInterestCount); }}
Java实现等额本金相关推荐
- JAVA计算等额本金还款列表
JAVA计算等额本金还款列表 公式 代码 运行结果 等额本金计算还款列表的代码来了~ 公式 月还本息=(本金/还款月数)+(本金-累计已还本金)×月利率 每月本金=总本金/还款月数 每月利息=(本金- ...
- Java计算等额本金和等额本息
Java计算等额本金和等额本息 等额本金 等额本息 等额本金 /*** 等额本金是指一种贷款的还款方式,是在还款期内把贷款数总额等分,每月偿还同等数额的本金和剩余贷款在该月所产生的利息,这样由于每月的 ...
- java 等额本金等额本息工具类
2019独角兽企业重金招聘Python工程师标准>>> 等额本息: /*** Description:等额本息工具类* Copyright: Copyright (corporati ...
- Java实现:房贷计算器 (关键词:公积金、首付、等额本息、等额本金)
1 背景:房贷计算器 目前现有的网页 房贷计算器,多多少少有点不符合自己需求,因此根据房贷相关公式及 java编写一个贷款计算器现有代码,改写了符合自己要求的 房贷计算器 . 计算结果精度为小数点后2 ...
- 贷款计算器- 等额本金、等额本息工具类(Java版)
/** * Description:等额本金工具类 * Copyright: Copyright (Corporation)2015 * Company: Corporation * @version ...
- Java Swing写简单计算器以及拓展贷款计算器(等额本息和等额本金计算可以单独拿出来用)
1. 简单计算器 纯手写 package com.jisuanqi;import com.sun.xml.internal.ws.util.StringUtils;import javax.swing ...
- 等额本金、等额本息工具类(Java版)
等额本息: /** * Description:等额本息工具类 * Copyright: Copyright (corporation)2015 * Company: Corporation * @a ...
- 等额本金,等额本息,随借随还,利随本清,按月付息到期还本,5种还款方式java计算方法
等额本金,等额本息,随借随还,利随本清,按月付息到期还本,5种还款方式java计算方法 等额本息定义:本金逐月递增,利息逐月递减,月还款数不变. 等额本金定义:本金保持相同,利息逐月递减,月还款数递减 ...
- Java之~ 等额本息,等额本金,组合贷
一,等额本息工具类 import java.math.BigDecimal; import java.text.DecimalFormat; import java.util.HashMap; imp ...
最新文章
- confluence中org.apache.tomcat.util.net.NioEndpoint$Acceptor.run Socket accept failed的解决方法
- 用户界面设计的技巧与技术 (作者Scott W.Ambler)
- [ZOJ 3203] 灯泡
- 前端面试题之http/HTML/浏览器(二)
- /etc/fstab 参数详解及如何设置开机自动挂载
- php include的路径问题,php7中include有相对路径无法打开
- koa2-cors应答跨域请求实现
- php ip操作,ip操作 · PHP 个人常用知识总结 · 看云
- 深入C++中构造函数、拷贝构造函数、赋值操作符、析构函数的调用过程总结
- 中文文本校对源码java_文字校对应该怎么校对?
- KITTI 3D目标检测数据集解析(完整版)
- Java实现抽象工厂模式
- 使用 Python爬虫+OpenCV 通过摄像头 二维码识别 来得到官方接口的反馈数据 从而实现实时准确地 检测健康码状态(获取JS动态数据)
- 跳房子(二维表上的搜索)
- 电信家庭宽带光猫端口映射实现外网访问家庭内网
- linux蓝牙obex协议,蓝牙协议英文缩写——记录
- 只需要一招,改变你的网易云皮肤(仅限于PC端)
- 粒子群算法的matlab实现
- N0.29——黑客技巧第一招:断网
- 一起来看流星雨剧情简介/剧情介绍/剧情分集介绍第十一集