贷款计算源码

/**
 * BankRefund.java
 * 版权所有(C) 2012 
 * 创建:cuiran 2012-10-15 14:51:21
 */
package com.wpndemo.bank;

import java.math.BigDecimal;

/**
 * 银行还款计算
 * @author cuiran
 * @version TODO
 */
public class BankRefund {

	/**
	 * 
	 * 等额本金还款法【利息少,但前期还的多】
	 * @param totalMoeny 贷款总额
	 * @param rate  贷款商业利率
	 * @param year  贷款年限
	 */
	public static void principal(int totalMoney,double rate,int year){
		/**
		 * 每月本金
		 */
		int totalMonth=year*12;
		double monthPri=totalMoney/totalMonth;
		/**
		 * 获取月利率
		 */
		double monRate=resMonthRate(rate);
		
		BigDecimal   b   =   new   BigDecimal(monRate);  
		monRate   =   b.setScale(6,   BigDecimal.ROUND_HALF_UP).doubleValue();  
		for(int i=1;i<=totalMonth;i++){
			double monthRes=monthPri+(totalMoney-monthPri*(i-1))*monRate;
			BigDecimal   b1   =   new   BigDecimal(monthRes);  
			monthRes   =   b1.setScale(2,   BigDecimal.ROUND_HALF_UP).doubleValue();  
			System.out.println("第"+i+"月,还款为:"+monthRes);
		}
	}
	/**
	 * 
	 * 等额本息还款【利息多】
	 * @param totalMoeny 贷款总额
	 * @param rate  贷款商业利率
	 * @param year  贷款年限
	 */
	public static void interest(int totalMoney,double rate,int year){
		/**
		 * 获取月利率
		 */
		double monRate=resMonthRate(rate);
		/**
		 * 月还款本息
		 */
		
		double monInterest=totalMoney*monRate*Math.pow((1+monRate),year*12)/(Math.pow((1+monRate),year*12)-1);
		BigDecimal   b   =   new   BigDecimal(monInterest);  
		   monInterest   =   b.setScale(2,   BigDecimal.ROUND_HALF_UP).doubleValue();  
		System.out.println("月供本息和:"+monInterest);
		
	}
	/**
	 * 
	 * 转换为月利率
	 * @param rate
	 * @return
	 */
	public static double resMonthRate(double rate){
		
		return rate/12;
	}
	/**
	 * TODO
	 * @param args
	 */
	public static void main(String[] args) {
		
		// TODO Auto-generated method stub
		int totalMoney=430000;
		double rate=0.0655;
		int year=20;
//		BankRefund.interest(totalMoney, rate, year);
		BankRefund.principal(totalMoney, rate, year);
		
	}

}


 

 

 

注明:本代码计算出的数据仅供参考,实际还需按照银行计算为准,谢谢!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

cuiran

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值