房贷计算


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

/**
*
* 等额本息还款【利息多】
*
* @param totalMoeny
* 贷款总额
* @param rate
* 贷款商业利率,年利率
* @param year
* 贷款年限
*/
public static void interest(double totalMoney, double rate, int year) {
interest(totalMoney, rate, year * 12, true);
}

/**
*
* 等额本息还款【利息多】
*
* @param totalMoeny
* 贷款总额
* @param rate
* 贷款商业利率,年利率
* @param month
* 月
*/
public static double interest(double totalMoney, double rate, int month,
boolean byMonth) {
/**
* 获取月利率
*/
double monRate = resMonthRate(rate);
/**
* 月还款本息
*/

double monInterest = totalMoney * monRate
* Math.pow((1 + monRate), month)
/ (Math.pow((1 + monRate), month) - 1);
BigDecimal b = new BigDecimal(monInterest);
monInterest = b.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
System.out.println("月供本息和:" + monInterest);
return monInterest;

}

/**
*
* 等额本金还款法【利息少,但前期还的多】
*
* @param totalMoeny
* 贷款总额
* @param rate
* 贷款商业利率
* @param year
* 贷款年限
*/
public static void principal(double 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 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);

}

}


循环本金利息借出:
public static void main3() {
backAmount = new ArrayList<Double>();
double iniAmount = 10000;
double iniRate = 0.18;
int month = 12;
double back = BankRefund.interest(iniAmount, iniRate, month, true);
System.out.println("第1个月收到:" + back);
double nowAmount = back;
for (int i = month - 1; i > 0; i--) {
double monthBack = BankRefund.interest(nowAmount, iniRate, i,
true);
nowAmount += monthBack;
System.out.println("第" + (month - i + 1) + "个月收到:" + nowAmount);
}
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值