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); } }