QLExpress计算等本等息、等额本息、等额本金
2017-05-08 09:03
253 查看
public class Interest {
private ExpressRunner runner = new ExpressRunner();
public void initial() throws Exception{
runner.addFunctionOfClassMethod("等本等息", Interest.class.getName(), "method1",new Class[] {double.class,double.class,int.class}, null);
runner.addFunctionOfClassMethod("等额本息", Interest.class.getName(), "method2",new Class[] {double.class,double.class,int.class}, null);
runner.addFunctionOfClassMethod("等额本金", Interest.class.getName(), "method3",new Class[] {double.class,double.class,int.class}, null);
}
public static void main(String[] args) throws Exception {
Interest indemo = new Interest();
indemo.initial();
Object r = indemo.runner.execute("等本等息(1000,0.008,12)", null, null, false, true);
System.out.println(r);
Object r2 = indemo.runner.execute("等额本息(1000,0.008,12)", null, null, false, true);
System.out.println(r2);
Object r3 = indemo.runner.execute("等额本金(1000,0.008,12)", null, null, false, true);
System.out.println("等额本金每个月的还款列表"+r3);
}
/**
* 等本等息还款方式计算每个月偿还本金和利息
* @param invest
* @param yearRate
* @param totalMonth
* @return
*/
public String method1(double invest,double yearRate,int totalMonth) {
double d = invest/totalMonth + invest*yearRate/totalMonth;
return "等本等息方式每个月应还款"+d;
}
/**
* 等额本息还款方式计算每月偿还本金和利息
* @param invest
* @param yearRate
* @param totalMonth
* @return
*/
public String method2(double invest, double yearRate, int totalMonth) {
double monthRate = yearRate / 12;
BigDecimal monthIncome = new BigDecimal(invest).multiply(new BigDecimal(monthRate * Math.pow(1 + monthRate, totalMonth))).divide(new BigDecimal(Math.pow(1 + monthRate, totalMonth)-1),2,BigDecimal.ROUND_DOWN);
return "等额本息方式每个月应还款"+monthIncome.doubleValue();
}
public Map<Integer, Double> method3(double invest, double yearRate, int totalMonth) {
Map<Integer, Double> map = new HashMap<Integer, Double>();
// 每月本金
double monthPri = getPerMonthPrincipal(invest, totalMonth);
// 获取月利率
double monthRate = yearRate / 12;
monthRate = new BigDecimal(monthRate).setScale(6, BigDecimal.ROUND_DOWN).doubleValue();
for (int i = 1; i <= totalMonth; i++) {
double monthRes = monthPri + (invest - monthPri * (i - 1)) * monthRate;
monthRes = new BigDecimal(monthRes).setScale(2, BigDecimal.ROUND_DOWN).doubleValue();
map.put(i, monthRes);
}
return map;
}
/**
* 等额本金计算获取还款方式为等额本金的每月偿还本金
*
* 公式:每月应还本金=贷款本金÷还款月数
*
* @param invest
* 总借款额(贷款本金)
* @param yearRate
* 年利率
* @param month
* 还款总月数
* @return 每月偿还本金
*/
public static double getPerMonthPrincipal(double invest, int totalMonth) {
BigDecimal monthIncome = new BigDecimal(invest).divide(new BigDecimal(totalMonth), 2, BigDecimal.ROUND_DOWN);
return monthIncome.doubleValue();
}
}
private ExpressRunner runner = new ExpressRunner();
public void initial() throws Exception{
runner.addFunctionOfClassMethod("等本等息", Interest.class.getName(), "method1",new Class[] {double.class,double.class,int.class}, null);
runner.addFunctionOfClassMethod("等额本息", Interest.class.getName(), "method2",new Class[] {double.class,double.class,int.class}, null);
runner.addFunctionOfClassMethod("等额本金", Interest.class.getName(), "method3",new Class[] {double.class,double.class,int.class}, null);
}
public static void main(String[] args) throws Exception {
Interest indemo = new Interest();
indemo.initial();
Object r = indemo.runner.execute("等本等息(1000,0.008,12)", null, null, false, true);
System.out.println(r);
Object r2 = indemo.runner.execute("等额本息(1000,0.008,12)", null, null, false, true);
System.out.println(r2);
Object r3 = indemo.runner.execute("等额本金(1000,0.008,12)", null, null, false, true);
System.out.println("等额本金每个月的还款列表"+r3);
}
/**
* 等本等息还款方式计算每个月偿还本金和利息
* @param invest
* @param yearRate
* @param totalMonth
* @return
*/
public String method1(double invest,double yearRate,int totalMonth) {
double d = invest/totalMonth + invest*yearRate/totalMonth;
return "等本等息方式每个月应还款"+d;
}
/**
* 等额本息还款方式计算每月偿还本金和利息
* @param invest
* @param yearRate
* @param totalMonth
* @return
*/
public String method2(double invest, double yearRate, int totalMonth) {
double monthRate = yearRate / 12;
BigDecimal monthIncome = new BigDecimal(invest).multiply(new BigDecimal(monthRate * Math.pow(1 + monthRate, totalMonth))).divide(new BigDecimal(Math.pow(1 + monthRate, totalMonth)-1),2,BigDecimal.ROUND_DOWN);
return "等额本息方式每个月应还款"+monthIncome.doubleValue();
}
public Map<Integer, Double> method3(double invest, double yearRate, int totalMonth) {
Map<Integer, Double> map = new HashMap<Integer, Double>();
// 每月本金
double monthPri = getPerMonthPrincipal(invest, totalMonth);
// 获取月利率
double monthRate = yearRate / 12;
monthRate = new BigDecimal(monthRate).setScale(6, BigDecimal.ROUND_DOWN).doubleValue();
for (int i = 1; i <= totalMonth; i++) {
double monthRes = monthPri + (invest - monthPri * (i - 1)) * monthRate;
monthRes = new BigDecimal(monthRes).setScale(2, BigDecimal.ROUND_DOWN).doubleValue();
map.put(i, monthRes);
}
return map;
}
/**
* 等额本金计算获取还款方式为等额本金的每月偿还本金
*
* 公式:每月应还本金=贷款本金÷还款月数
*
* @param invest
* 总借款额(贷款本金)
* @param yearRate
* 年利率
* @param month
* 还款总月数
* @return 每月偿还本金
*/
public static double getPerMonthPrincipal(double invest, int totalMonth) {
BigDecimal monthIncome = new BigDecimal(invest).divide(new BigDecimal(totalMonth), 2, BigDecimal.ROUND_DOWN);
return monthIncome.doubleValue();
}
}
相关文章推荐
- 等额本金和等额本息的区别(含计算公式)
- BigDecimal用法之计算等额本金和等额本息
- 等额本金和等额本息的区别(含计算公式)
- [转]详细说明等额本金和等额本息的计算方式与利弊
- 等额本息及等额本金计算公式
- BigDecimal用法之计算等额本金和等额本息
- java等额本息、等额本金计算(用了好久才知道等额本息原来这样算,记录一下)
- javascript根据输入的本金实时计算本息和
- java等额本金、等额本息计算
- 等额本金VS等额本息
- 等额本息与等额本金
- PHP房贷计算器实例代码,等额本息,等额本金
- 基于“总价、首付、贷款年限、利息、贷款额度”信息,计算每月最低还款额度。需要能按“等额本金、等额本息”两种形式计算还款
- 等额本息计算公式推导
- 等额本息计算方法
- python for android : 贷款等额本息每月还款额计算
- 银行业务中贷款算法等额本金等额本息算法程序
- C语言:房贷计算器(等额本息与等额本金对比计算器)
- PHP房贷计算器代码,等额本息,等额本金
- 计算银行还款 等额本金 85折 20年