/**
* @创建者 CSDN_LQR
* @描述 贷款计算工具
*/
public class CalculatorUtils {
public static void main(String[] args) {
CalculatorUtils utils = new CalculatorUtils();
//等额本息、商贷、根据总额
// CalculatorBean calculatorBean = utils.calcLoanOrFundByTotalPrice(REFUND_TYPE.AVERAGE_PRINCIPAL, LOAN_TYPE.LOAN, 240, 5.15f, 0, 10000);
//等额本息、公积金、根据总额
// CalculatorBean calculatorBean = utils.calcLoanOrFundByTotalPrice(REFUND_TYPE.AVERAGE_PRINCIPAL, LOAN_TYPE.FUND, 240, 0, 5.15f, 10000);
//等额本息、商贷、根据单价和面积
CalculatorBean calculatorBean = utils.calcLoanOrFundByUnitPriceAndArea(REFUND_TYPE.AVERAGE_PRINCIPAL, LOAN_TYPE.LOAN, 240, 1000f, 10f, 0.2f, 5.15f);
//等额本息、公积金、根据单价和面积
// CalculatorBean calculatorBean = utils.calcLoanOrFundByUnitPriceAndArea(REFUND_TYPE.AVERAGE_PRINCIPAL, LOAN_TYPE.FUND, 240, 1000f, 10f, 0.2f, 5.15f);
System.out.println("月均还款:" + calculatorBean.pricePerMonth);
System.out.println("房款总额:" + calculatorBean.total_price);
System.out.println("贷款总额:" + calculatorBean.loan_amount);
System.out.println("还款总额:" + calculatorBean.totalPriceHuankuan);
System.out.println("支付利息款:" + calculatorBean.totalInterest);
System.out.println("首期付款 :" + calculatorBean.down_payment);
System.out.println("贷款月数 :" + calculatorBean.mortgage_month);
}
//还款方式
public static class REFUND_TYPE {
public static int AVERAGE_PRINCIPAL = 1;//等额本息
public static int AVERAGE_CAPITAL = 2;//等额本金
}
//贷款类别
public static class LOAN_TYPE {
public static int LOAN = 1;//商贷
public static int FUND = 2;//公积金
public static int PORTFOLIO = 3;//组合贷
}
//计算方式
public static class CALCULATION_TYPE {
public static int TOTAL_LOANS = 1; // 根据贷款总额
public static int UNIT_PRICE_AND_AREA = 2; // 根据单价和面积
}
/**
* 计算 商贷||公积金(根据总价)
*
* @param refund_type 还款方式(等额本息、等额本金)
* @param loan_type 贷款类别(商贷、公积金)
* @param mortgage_month 贷款月数
* @param interest 商贷利率/公积金贷款利率
* @param total_price 房款总额
* @return
*/
public CalculatorBean calcLoanOrFundByTotalPrice(int refund_type, int loan_type, int mortgage_month, double interest, double total_price) {
if (loan_type == LOAN_TYPE.LOAN) {
return coreCalculate(refund_type, loan_type, mortgage_month, CALCULATION_TYPE.TOTAL_LOANS, 0, 0, 0, interest, 0, total_price, 0, 0);
} else {
return coreCalculate(refund_type, loan_type, mortgage_month, CALCULATION_TYPE.TOTAL_LOANS, 0, 0, 0, 0, interest, total_price, 0, 0);
}
}
/**
* 计算 商贷||公积金(根据单价和面积)
*
* @param refund_type 还款方式(等额本息、等额本金)
* @param loan_type 贷款类别(商贷、公积金)
* @param mortgage_month 贷款月数
* @param single_price 单价
* @param area 面积
* @param mortgage_ratio 按揭成数
* @param interest 商贷利率/公积金贷款利率
* @return
*/
public CalculatorBean calcLoanOrFundByUnitPriceAndArea(int refund_type, int loan_type, int mortgage_month, double single_price, double area, double mortgage_ratio, double interest) {
if (loan_type == LOAN_TYPE.LOAN) {
return coreCalculate(refund_type, loan_type, mortgage_month, CALCULATION_TYPE.UNIT_PRICE_AND_AREA, single_price, area, mortgage_ratio, interest, 0, 0, 0, 0);
} else {
return coreCalculate(refund_type, loan_type, mortgage_month, CALCULATION_TYPE.UNIT_PRICE_AND_AREA, single_price, area, mortgage_ratio, 0, interest, 0, 0, 0);
}
}
//计算 组合贷
public CalculatorBean calcPortfolio(int refund_type, int mortgage_month, double loan_interest, double fund_interest, double shangyexing, double gongjijin) {
return coreCalculate(refund_type, LOAN_TYPE.PORTFOLIO, mortgage_month, 0, 0, 0, 0, loan_interest, fund_interest, 0, shangyexing, gongjijin);
}
//计算 商贷||公积金
private CalculatorBean calcLoanOrFund(int refund_type, int loan_type, int mortgage_month, int loan_totalprice_type, double single_price, double area, int mortgage_ratio, double loan_interest, double fund_interest, double total_price) {
return coreCalculate(refund_type, loan_type, mortgage_month, loan_totalprice_type, single_price, area, mortgage_ratio, loan_interest, fund_interest, total_price, 0, 0);
}
/**
* @param refund_type 还款方式(AVERAGE_PRINCIPAL、AVERAGE_CAPITAL)
* @param loan_type 贷款类别(商贷、公积金、组合贷)
* @param mortgage_month 贷款月数
* @param loan_totalprice_type 计算方式(TOTAL_LOANS、UNIT_PRICE_AND_AREA)
* <p>
* //根据根据单价和面积
* @param single_price 单价
* @param area 面积
* @param mortgage_ratio 按揭成数
* @param loan_interest 商贷利率
* @param fund_interest 公积金贷款利率
* @param total_price 房款总额
* <p>
* //组合贷
* @param shangyexing 商业性
* @param gongjijin 公积金
*/
private CalculatorBean coreCalculate(int refund_type, int loan_type, int mortgage_month, int loan_totalprice_type, double single_price, double area, double mortgage_ratio, double loan_interest, double fund_interest, double total_price, double shangyexing, double gongjijin) {
CalculatorBean calculatorBean = new CalculatorBean();
double interest_rate = 0;//利率(商贷利率/公积金贷款利率)
double loan_amount = 0;//贷款总额
double down_payment = 0;//首期付款
// 商贷 || 公积金
if (loan_type == LOAN_TYPE.LOAN || loan_type == LOAN_TYPE.FUND) {
//计算利率
interest_rate = loan_type == LOAN_TYPE.LOAN ? ArithUtil.div(loan_interest, 100) : ArithUtil.div(fund_interest, 100);
// 根据单价和面积
if (loan_totalprice_type == CALCULATION_TYPE.UNIT_PRICE_AND_AREA) {
total_price = ArithUtil.mul(single_price, area);// 单 价 * 面 积
loan_amount = ArithUtil.mul(total_price, mortgage_ratio);// 总价 * 按揭成数
down_payment = ArithUtil.sub(total_price, loan_amount);// 总价 - 贷款额
}
// 根据贷款总额
else if (loan_totalprice_type == CALCULATION_TYPE.TOTAL_LOANS) {
loan_amount = total_price;
down_payment = 0;
}
calculatorBean = getRightInfoNotComb(loan_amount, mortgage_month, interest_rate, refund_type);
}
// 组合贷
else if (loan_type == LOAN_TYPE.PORTFOLIO) {
loan_amount = ArithUtil.add(shangyexing, gongjijin);
calculatorBean = getRightInfoComb(shangyexing, loan_interest, gongjijin, fund_interest, mortgage_month, refund_type);
}
//填充其他数据
calculatorBean.total_price = total_price;
calculatorBean.loan_amount = loan_amount;
calculatorBean.down_payment = down_payment;
calculatorBean.mortgage_month = mortgage_month;
return calculatorBean;