工具类:

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.HashMap;
import java.util.Map;/*** 等额本息计算工具类** <p>* 等额本息还款,也称定期付息,即借款人每月按相等的金额偿还贷款本息,其中每月贷款利息按月初剩余贷款本金计算并逐月结清。把按揭贷款的本金总额与利息总额相加,* 然后平均分摊到还款期限的每个月中。作为还款人,每个月还给银行固定金额,但每月还款额中的本金比重逐月递增、利息比重逐月递减。*/
public class AverageCapitalPlusInterestUtils {/*** 每月偿还本金和利息* <p>* 公式:每月偿还本息=〔贷款本金×月利率×(1+月利率)^还款月数〕÷〔(1+月利率)^还款月数-1〕** @param invest     总借款额(贷款本金,单位分)* @param yearRate   年利率* @param totalMonth 还款总月数* @return 每月偿还本金和利息(入1 单位分)*/public static long getPerMonthPrincipalInterest(long invest, double yearRate, int totalMonth) {double monthRate = yearRate / 12;double perMonthPrincipalInterest = invest * (monthRate * Math.pow(1 + monthRate, totalMonth))/(Math.pow(1 + monthRate, totalMonth) - 1);return new BigDecimal(perMonthPrincipalInterest).setScale(0, BigDecimal.ROUND_HALF_UP).longValue();}/*** 等额本息的每月偿还利息* <p>* 公式:每月偿还利息=贷款本金×月利率×〔(1+月利率)^还款月数-(1+月利率)^(还款月序号-1)〕÷〔(1+月利率)^还款月数-1〕** @param invest     总借款额(贷款本金,分)* @param yearRate   年利率* @param totalMonth 还款总月数* @return 每月偿还利息(入1 单位分)*/public static Map<Integer, Long> getPerMonthInterest(long invest, double yearRate, int totalMonth) {Map<Integer, Long> map = new HashMap<>();double monthRate = yearRate / 12;double monthInterest;for (int i = 1; i < totalMonth + 1; i++) {double multiply = invest * monthRate;double sub = Math.pow(1 + monthRate, totalMonth) - Math.pow(1 + monthRate, i - 1);monthInterest = multiply * sub/(Math.pow(1 + monthRate, totalMonth) - 1);map.put(i, new BigDecimal(monthInterest).setScale(0, BigDecimal.ROUND_HALF_UP).longValue());}return map;}/*** 等额本息的每月偿还本金(月还本息-月还利息)** @param invest     总借款额(贷款本金,分)* @param yearRate   年利率* @param totalMonth 还款总月数* @return 每月偿还本金(取整舍 单位分)*/public static Map<Integer, Long> getPerMonthPrincipal(long invest, double yearRate, int totalMonth) {double monthRate = yearRate / 12;double monthIncome = invest * monthRate * Math.pow(1 + monthRate, totalMonth)/(Math.pow(1 + monthRate, totalMonth) - 1);long perMonthPrincipalInterest = new BigDecimal(monthIncome).setScale(0, BigDecimal.ROUND_HALF_UP).longValue();Map<Integer, Long> mapPrincipal = new HashMap<>();double monthInterest;for (int i = 1; i < totalMonth + 1; i++) {Double multiply = invest * monthRate;double sub = (Math.pow(1 + monthRate, totalMonth)) - (Math.pow(1 + monthRate, i - 1));monthInterest = multiply* sub/(Math.pow(1 + monthRate, totalMonth) - 1);long monthInterestL = new BigDecimal(monthInterest).setScale(0, BigDecimal.ROUND_HALF_UP).longValue();mapPrincipal.put(i, perMonthPrincipalInterest-monthInterestL);}return mapPrincipal;}/*** 等额本息的总利息** @param invest     总借款额(贷款本金)* @param yearRate   年利率* @param totalMonth 还款总月数* @return 总利息 (单位分)*/public static long getInterestCount(long invest, double yearRate, int totalMonth) {long count = 0;Map<Integer, Long> mapInterest = getPerMonthInterest(invest, yearRate, totalMonth);for (Map.Entry<Integer, Long> entry : mapInterest.entrySet()) {count = count + entry.getValue();}return count;}}

运行:

public static void main(String[] args) {long invest = 10000; // 本金int month = 6;double yearRate = 0.1; // 年利率long perMonthPrincipalInterest = getPerMonthPrincipalInterest(invest, yearRate, month);System.out.println("等额本息---每月还款本息:" + perMonthPrincipalInterest);Map<Integer, Long> mapInterest = getPerMonthInterest(invest, yearRate, month);System.out.println("等额本息---每月还款利息:" + mapInterest);Map<Integer, Long> mapPrincipal = getPerMonthPrincipal(invest, yearRate, month);System.out.println("等额本息---每月还款本金:" + mapPrincipal);long count = getInterestCount(invest, yearRate, month);System.out.println("等额本息---总利息:" + count);for(int i=1;i<month + 1;i++){if(i<month){System.out.println("等额本息---"+i+"月还款本金:" + mapPrincipal.get(i) + ",还款利息:" + mapInterest.get(i));invest = invest - mapPrincipal.get(i);} else {System.out.println("等额本息---"+i+"月还款本金:" +invest + ",还款利息:" + (perMonthPrincipalInterest - invest));}}}

效果截图:

Java等额本息算法实现相关推荐

  1. Java等额本息实现

    工具类 import java.math.BigDecimal; import java.util.HashMap; import java.util.Map;/*** 等额本息计算工具类** < ...

  2. java 等额本息计算方式

    投资理财,等额本息计算方式 以下按照10000元,以年利率15.5%,投资期限为6个月,以等额本息方式偿还来计算 /*** 等额本息计算*/ public class PrincipalAndInte ...

  3. Java等额本息年化利率,转等本等息月利率

    public static void main(String[] args) {double interest = 0.237;//年化利率int period = 18;//期数BigDecimal ...

  4. python 计算银行带宽等额本金和等额本息的方法

    在房屋贷款中,还款是按月进行的,利息也是按月计算的(月利率为年利率除以12),每月还款优先还本月利息,剩下的还本金,未还款的本金会影响下月利息的计算,在还款期数达到时,所有贷款都会还完,还款选项中有等 ...

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

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

  6. 等额本息还款方式的年利率计算方法及java代码实现

    等额本息还款方式在生活中是很常用的,比如贷款买房,买车,信用卡分期还款,京东白条分期 ,等等,只要是借了钱,每月还款金额一样的,都属于等额本息的方式.有些时候我们贷款后,商家或银行告诉了每期的还款额, ...

  7. 银行业务中贷款算法等额本金等额本息算法程序

    写一个贷款计算器,从网上找了一个算法,自己改了改可以用了,不错,分享给大家 import java.text.DecimalFormat; public class jshk { public sta ...

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

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

  9. MATLAB等额还款代码,matlab算法实现对等额本息和等额本金两种还款方式的计算

    matlab算法实现对等额本息和等额本金两种还款方式的计算 发布时间:2018-05-29 20:04, 浏览次数:1410 , 标签: matlab matlab算法实现对等额本息和等额本金两种还款 ...

  10. Java实现等额本息

    import java.math.BigDecimal; import java.text.SimpleDateFormat; import java.util.Calendar; import ja ...

最新文章

  1. 两步设置:visual studio code(vscode)如何设置文本自动换行
  2. 这些年微软相关的技术总结, Javascript在客户端的使用
  3. 地图漫游功能的具体体现_一卡通考勤门禁管线系统主要模块功能说明
  4. arduino服务器_如何使用Arduino检查Web服务器的响应状态
  5. 1040. 有几个PAT(25
  6. Java笔记-Spring Boot JDBC连接Oracle数据库
  7. [绝对原创]一些你们想不到的简单方法,就可以让你手机飞快起来!!!
  8. MVC3.0 中Razor 学习
  9. Trick(十一)—— list of lists 每一个属性列的获取
  10. gis数据与cad数据转换之间的关系
  11. 微信小程序开发工具显示网络错误
  12. Improved Zero-shot Neural Machine Translation via Ignoring Spurious Correlations
  13. 实训项目:PHP双色球效果实现
  14. python学习笔记_week19
  15. Lifeline功能介绍01——日历及时间轴的查看
  16. 零基础学python难吗?python自学难吗?
  17. 故杀敌者,怒也;取敌之利者,货也
  18. 【图像原理】rgb数字图片概念之显示器成像原理
  19. 路由算法之——ECMP算法的改进方向
  20. HDU1814 Peaceful Commission 2SAT

热门文章

  1. 选择排序为什么是不稳定的?
  2. SI24R1调试接收方能接收到数据,但发送方提示发送超时失败
  3. 数据结构——散列表--线性探测法
  4. 微信公众平台测试帐号申请及Token验证地址提供
  5. python中index什么意思_index在python中是什么意思
  6. 机器学习实战——3.4 示例:使用决策树预测隐形眼镜类型
  7. 使用数据驱动进行配对交易:简单交易策略
  8. ps批量修改名片文字_pS如何在图中添加和修改文字
  9. windows安全中心打不开defender的完美解决方法,适用于win11更新后进入defender提示需要新应用或者Windows安全中心出错,或者账户更换后出现此问题。
  10. 数据不正态分布如何办?