计算按揭明细记录的类:
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.math.RoundingMode;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
/**
* @author Alfoo Liu <dmcpxy@Gmail.com>
* @since 2011-11-01 09:58
*/
public class MortgageCalculator {
final static String default_config_file_name = "MortgageCalculator.properties";
SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd");
DecimalFormat df = new DecimalFormat("0.00");
DecimalFormat dfl = new DecimalFormat("0.0000");
private Properties configuration = new Properties();
public MortgageCalculator(String configFilePath) {
df.setRoundingMode(RoundingMode.UP);
dfl.setRoundingMode(RoundingMode.UP);
loadProperties(configFilePath);
}
public void loadProperties(String filePath) {
try {
FileInputStream fileInputStream = new FileInputStream(filePath);
configuration.load(fileInputStream);
} catch (FileNotFoundException fnfe) {
InputStream resourceAsStream = getClass().getResourceAsStream(default_config_file_name);
try {
configuration.load(resourceAsStream);
} catch (IOException e) {
System.err.println("failed read config file: " + default_config_file_name + " from classpath "
+ this.getClass().getPackage().getName());
}
} catch (IOException ioe) {
System.err.println("failed read config file: " + filePath);
}
}
public Properties getConfiguration() {
return configuration;
}
public void printMortgageDetailInfo(List<MortgageBean> payList) {
for (MortgageBean bean : payList) {
System.out.println(bean.toString());
}
}
/**
* calculte method: (total - benjin_money * cur_month) * rate_month + benjin_money;
* @return List pay list;
*/
public List<MortgageBean> calculate() {
List<MortgageBean> payList = new ArrayList<MortgageBean>();
int period = getPeriod(), restPeriod;
double totalPrincipal = getTotalPrincipal();
String currentDateStr = getFirstPayDate();
double restPrincipal = totalPrincipal, interest, principal, rate, monthRate;
rate = getFirstPayRate();
Date currentDate;
MortgageBean mortgageBean;
for (int i = 1; i <= period; i++) {
monthRate = toDouble( dfl.format( rate / 12 ) );
restPeriod = period - i + 1;
principal = toDouble( df.format( (restPrincipal / restPeriod) ) );
String tiqianhuankuanDate = getConfiguration().getProperty("tiqianhuankuanDate");
if (null != tiqianhuankuanDate && tiqianhuankuanDate.equals(currentDateStr)) {
principal += toDouble( getConfiguration().getProperty("tiqianhuankuanMoney", "0") );
}
interest = toDouble( df.format( (restPrincipal - principal) * monthRate ) );
restPrincipal = toDouble(df.format(restPrincipal - principal));
currentDate = getDate(currentDateStr);
mortgageBean = new MortgageBean(currentDate, i, rate, toDouble( df.format(principal + interest) ),
principal, interest, restPrincipal);
payList.add(mortgageBean);
currentDateStr = getNextPayDate(currentDate);
rate = toDouble( dfl.format( getNextPayRate(currentDate, rate) ) );
}
return payList;
}
protected double toDouble(String dv) {
return Double.parseDouble(dv);
}
private double getDiscount() {
return Double.parseDouble(getConfiguration().getProperty("rateDiscount"));
}
private int getPeriod() {
return Integer.parseInt( getConfiguration().getProperty("periods") );
}
private double getTotalPrincipal() {
return Double.parseDouble(getConfiguration().getProperty("totalPrincipal"));
}
private String getFirstPayDate() {
return configuration.getProperty("firstMortgageDate");
}
private Date getDate(String date) {
try {
return format.parse(date);
} catch (ParseException e) {
System.err.println("invalid date format: " + date);
return null;
}
}
private double getFirstPayRate() {
String firstPayDate = "MortgageRate." + getFirstPayDate();
String firstRateStr = configuration.getProperty(firstPayDate);
double v = Double.parseDouble(firstRateStr)/100 * getDiscount();
return toDouble( dfl.format(v) );
}
private String getNextPayDate(Date date) {
GregorianCalendar gc = new GregorianCalendar(Locale.SIMPLIFIED_CHINESE);
gc.setTime(date);
gc.add(Calendar.MONTH, 1);
Date nextMonth = gc.getTime();
return format.format(nextMonth);
}
private double getNextPayRate(Date date, double lastPayRate) {
String property = configuration.getProperty("MortgageRate." + getNextPayDate(date));
if (null == property) {
return lastPayRate;
}
double v = Double.parseDouble(property) * getDiscount() / 100;
return toDouble( dfl.format(v) );
}
public static void main(String[] args) {
MortgageCalculator calculator = new MortgageCalculator("");
calculator.loadProperties("");
List<MortgageBean> mortgageBeanList = calculator.calculate();
calculator.printMortgageDetailInfo(mortgageBeanList);
}
}
按揭的Bean类:
import java.io.Serializable;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
* @author Alfoo Liu <dmcpxy@Gmail.com>
* @since 2011-11-01 10:36
*/
public class MortgageBean implements Serializable {
DecimalFormat df = new DecimalFormat("0.00");
DecimalFormat dfl = new DecimalFormat("0.00%");
final static SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
final static String DELIMETER = "\t\t";
private Date mortgageDate;
private int mortgageNumber;
private double rate;
/*当前月份还的款总额*/
private double currentMonthPay;
/*当前月份还的本金*/
private double currentMonthPrincipal;
/*当前月还的利息*/
private double currentMonthInterest;
/*剩余本金*/
private double restPrincipal;
public MortgageBean(Date mortgageDate, int mortgageNumber, double rate, double currentMonthPay,
double currentMonthPrincipal, double currentMonthInterest, double restPrincipal) {
this.mortgageDate = mortgageDate;
this.mortgageNumber = mortgageNumber;
this.rate = rate;
this.currentMonthPay = currentMonthPay;
this.currentMonthPrincipal = currentMonthPrincipal;
this.currentMonthInterest = currentMonthInterest;
this.restPrincipal = restPrincipal;
}
public Date getMortgageDate() {
return mortgageDate;
}
public void setMortgageDate(Date mortgageDate) {
this.mortgageDate = mortgageDate;
}
public int getMortgageNumber() {
return mortgageNumber;
}
public void setMortgageNumber(int mortgageNumber) {
this.mortgageNumber = mortgageNumber;
}
public double getRate() {
return rate;
}
public void setRate(float rate) {
this.rate = rate;
}
public double getCurrentMonthPay() {
return currentMonthPay;
}
public void setCurrentMonthPay(float currentMonthPay) {
this.currentMonthPay = currentMonthPay;
}
public double getCurrentMonthPrincipal() {
return currentMonthPrincipal;
}
public void setCurrentMonthPrincipal(float currentMonthPrincipal) {
this.currentMonthPrincipal = currentMonthPrincipal;
}
public double getCurrentMonthInterest() {
return currentMonthInterest;
}
public void setCurrentMonthInterest(float currentMonthInterest) {
this.currentMonthInterest = currentMonthInterest;
}
public double getRestPrincipal() {
return restPrincipal;
}
public void setRestPrincipal(float restPrincipal) {
this.restPrincipal = restPrincipal;
}
@Override public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(format.format( getMortgageDate() ));
sb.append(DELIMETER);
sb.append( getMortgageNumber() );
sb.append(DELIMETER);
sb.append( dfl.format(getRate()) );
sb.append(DELIMETER);
sb.append( df.format(getCurrentMonthPay()) );
sb.append(DELIMETER);
sb.append( df.format(getCurrentMonthPrincipal()) );
sb.append(DELIMETER);
sb.append( df.format(getCurrentMonthInterest()) );
sb.append(DELIMETER);
sb.append( df.format(getRestPrincipal()) );
return sb.toString();
}
}
配置文件,放在这个类相同的目录下:
#如果你家的还款日期是26号,则把日期的末两位全部改成26,日期格式为yyyyMMdd
#format: yyyyMMdd
firstMortgageDate=20100326
#第一次还款的利率
firstMortgageRate=5.94
#利率折扣
rateDiscount=0.7
#Unit: Month
periods=240
#Unit: yuan
totalPrincipal=300000
#提前还款月份
tiqianhuankuanDate=20111226
#Unit: yuan
tiqianhuankuanMoney=80000
#各期还款利率
MortgageRate.20100326=5.94
MortgageRate.20101026=6.14
MortgageRate.20101226=6.40
MortgageRate.20110226=6.60
MortgageRate.20110426=6.80
MortgageRate.20110726=7.05
分享到:
相关推荐
本项目“matlab gui编写的按揭贷款计算器”正是结合了MATLAB的编程能力和GUI设计,为用户提供了计算按揭贷款的便捷工具。 1. **MATLAB GUI基础** MATLAB GUI是通过 GUIDE(Graphical User Interface Development ...
在本文档中,我们探讨了如何使用WPS 2021表格来计算按揭贷款的月供明细账。这通常对于购房者来说是一项重要的任务,尤其是对于需要贷款的年轻人,了解月供的计算方法和不同还款策略可以帮助他们做出更明智的财务决策...
目前最稳定、最详细的按揭还贷计数器,可导出结果到文本,与银行答应的还贷明细相同
本文主要介绍了如何使用WPS 2021表格计算按揭贷款的月供明细账,帮助用户了解两种主要的还款方式——等额本息和等额本金,并通过实际操作展示如何在WPS表格中进行计算。 首先,我们来看两种还款方式的计算公式: 1...
【VB 按揭贷款计算程序】是一种使用Visual Basic(VB)编程语言开发的应用程序,主要用于帮助用户计算按揭贷款的月供、总利息以及贷款周期内的还款总额。在房地产交易中,按揭贷款是购房者向银行或其他金融机构借款...
银行按揭贷款计算软件是专为购房者设计的一款实用工具,它可以帮助用户快速、准确地计算出贷款购房所需支付的月供、利息总额以及贷款期限内的总成本。在进行购房决策时,了解这些关键数据至关重要,因为它们直接影响...
在Excel中,我们可以利用财务函数来计算住房按揭的还款计划。这是一项非常实用的技能,尤其对于财务人员和购房者来说。在这个例子中,我们有20万元的贷款,期限为5年,年利率为6%。我们需要计算每月末应还的本金和...
最新商业银行按揭贷款计算工具,完全免费,无功能限制,程序功能齐全,设置灵活简单。同时满足公积金贷款和个人商业贷款的组合贷款,并具有打印每月还款计划表功能,是购房按揭贷款人士的好帮手。
3. **计算逻辑**:编写计算月供、总利息和贷款总额的算法。这通常会涉及到数学公式,例如等额本息的月供计算公式是:`M = P * r * (1+r)^n / [(1+r)^n - 1]`,其中M为月供,P为贷款金额,r为月利率,n为贷款期数(月...
购房按揭计算表解压密码:excelhome
方便计算银行按揭计算每月应还款金额,及总还款金额和利息。可以按两种方式计算,每月等额还款和按月递减还款。所用控件:ehlib3.0 fastreport2.47,grid toxls(在压缩包已包含)。
2. **计算逻辑**:编写Java函数来实现按揭贷款的计算,这部分可能会包含上述的等额本息或等额本金的计算公式。 3. **事件监听**:设置按钮的OnClickListener,当用户点击按钮时调用计算逻辑,并更新结果显示视图。 4...
房屋按揭计算是购买房产时一个重要的财务规划环节,它涉及到购房者与银行之间的贷款协议,以及个人长期的财务支出。本资料"房屋按揭计算表.zip"包含了一份名为"房屋按揭计算表.xls"的Excel文件,这是一份用于帮助...
按揭计算EXCEL-等额本金计算器.pdf 本资源是关于Excel按揭计算的等额本金计算器,主要用于计算等额本金的还款金额和还款期限。下面是该资源的详细知识点: 1. 等额本金计算器的定义 等额本金计算器是指一种计算...
在Android开发领域,银行按揭贷款的基本计算功能是常见的需求之一。这个压缩包"Android 银行按揭贷款基本计算功能源码.zip"提供了一套实现此类功能的源代码,可以帮助开发者理解如何在Android应用中实现贷款计算的...
在《购房按揭计算》中,VB.NET被用来编写用户界面和业务逻辑,实现按揭计算和存款计划的算法。 3. **控件应用**: 在VB.NET中,控件是构建用户界面的基本元素,如文本框、按钮、标签等。软件中的控件可能包括输入...
在购房过程中,计算按揭贷款是一项必不可少的任务,而"按揭计算器"正是为了帮助我们简化这一过程而设计的工具。它以简洁的操作界面和强大的计算功能,为购房者提供了极大的便利。下面,我们将深入探讨按揭计算器的...
房屋按揭计算表.xls