房贷计算_JAVA_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > JAVA > 房贷计算

房贷计算

 2013/9/2 1:09:27  zheyiw  程序员俱乐部  我要评论(0)
  • 摘要:/***银行还款计算**@authorcuiran*@versionTODO*/publicclassBankRefund{/****等额本息还款【利息多】**@paramtotalMoeny*贷款总额*@paramrate*贷款商业利率,年利率*@paramyear*贷款年限*/publicstaticvoidinterest(doubletotalMoney,doublerate,intyear){interest(totalMoney,rate,year*12,true);
  • 标签:
class="java">
/**
 * 银行还款计算
 * 
 * @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);
		}
	}
  • 相关文章
发表评论
用户名: 匿名