合同开始日期:2023-01-01,结束日期:2026-01-01,免租起始期:2023-01-01,免租终止日期:023-01-31,计费面积:100平方米,月租单价20/平方米,计算方式:每3月计算产生一条记录,收款方式为按3个月收一次,提前收款期为1个月,基本租期1年,超过基本租期后按1年一个递增周期,递增周期内月租单价按上一周期内月租单价递增一次,年递增率为6%;按java7来实现:按计算方式产生合同期内含收款日期、租期起始日期、租期终止日期、租期单价、租期(月数)租金的计划列表,生成一个完整示例并配上说明
时间: 2024-01-31 10:03:21 浏览: 139
0500103-场地租赁协议.zip
好的,我来为您解答问题。首先,根据您提供的合同信息,我会按照计算方式,生成合同期内的租金计划列表,并且包含收款日期、租期起始日期、租期终止日期、租期单价、租期(月数)和租金。以下是示例代码:
```java
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
public class RentCalculator {
// 合同开始日期
private static final Date START_DATE = new Date(1230768000000L); // 2023-01-01
// 合同结束日期
private static final Date END_DATE = new Date(1651545600000L); // 2026-01-01
// 免租起始日期
private static final Date FREE_START_DATE = new Date(1230768000000L); // 2023-01-01
// 免租终止日期
private static final Date FREE_END_DATE = new Date(1233446400000L); // 2023-01-31
// 计费面积
private static final BigDecimal AREA = new BigDecimal("100");
// 月租单价
private static final BigDecimal UNIT_PRICE = new BigDecimal("20");
// 基本租期,单位:月
private static final int BASE_TERM = 12;
// 递增周期,单位:年
private static final int INCREMENT_CYCLE = 1;
// 递增率,单位:百分比
private static final BigDecimal INCREMENT_RATE = new BigDecimal("6");
public static void main(String[] args) {
List<RentPlan> rentPlanList = calculateRentPlan();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
System.out.println("收款日期\t租期起始日期\t租期终止日期\t租期单价\t租期(月数)\t租金");
for (RentPlan rentPlan : rentPlanList) {
System.out.println(sdf.format(rentPlan.getPaymentDate()) + "\t" +
sdf.format(rentPlan.getStartDate()) + "\t" +
sdf.format(rentPlan.getEndDate()) + "\t" +
rentPlan.getUnitPrice() + "\t" +
rentPlan.getTerm() + "\t" +
rentPlan.getRent());
}
}
/**
* 计算租金计划列表
*
* @return 租金计划列表
*/
public static List<RentPlan> calculateRentPlan() {
List<RentPlan> rentPlanList = new ArrayList<>();
BigDecimal currentUnitPrice = UNIT_PRICE; // 当前租期单价
Date currentDate = START_DATE; // 当前日期
while (currentDate.before(END_DATE)) {
// 计算租期起始日期和租期终止日期
Date startDate = currentDate;
Calendar calendar = Calendar.getInstance();
calendar.setTime(startDate);
calendar.add(Calendar.MONTH, BASE_TERM);
Date endDate = calendar.getTime();
if (endDate.after(END_DATE)) {
endDate = END_DATE;
}
// 计算租期单价
BigDecimal unitPrice = currentUnitPrice;
if (startDate.after(FREE_START_DATE) && startDate.before(FREE_END_DATE)) {
unitPrice = BigDecimal.ZERO;
}
// 计算租期(月数)
int term = getMonthDiff(startDate, endDate);
// 计算租金
BigDecimal rent = AREA.multiply(unitPrice).multiply(new BigDecimal(term));
rent = rent.setScale(2, RoundingMode.HALF_UP);
// 计算收款日期
calendar.setTime(endDate);
calendar.add(Calendar.MONTH, -1);
calendar.add(Calendar.DAY_OF_MONTH, 1);
Date paymentDate = calendar.getTime();
// 添加租金计划
RentPlan rentPlan = new RentPlan(paymentDate, startDate, endDate, unitPrice, term, rent);
rentPlanList.add(rentPlan);
// 更新当前日期和当前租期单价
currentDate = endDate;
if (getYearDiff(START_DATE, currentDate) % INCREMENT_CYCLE == 0) {
currentUnitPrice = currentUnitPrice.multiply(INCREMENT_RATE.add(new BigDecimal("100")))
.divide(new BigDecimal("100"), 2, RoundingMode.HALF_UP);
}
}
return rentPlanList;
}
/**
* 计算两个日期之间的月份差
*
* @param startDate 开始日期
* @param endDate 结束日期
* @return 月份差
*/
private static int getMonthDiff(Date startDate, Date endDate) {
Calendar startCalendar = Calendar.getInstance();
startCalendar.setTime(startDate);
int startYear = startCalendar.get(Calendar.YEAR);
int startMonth = startCalendar.get(Calendar.MONTH);
Calendar endCalendar = Calendar.getInstance();
endCalendar.setTime(endDate);
int endYear = endCalendar.get(Calendar.YEAR);
int endMonth = endCalendar.get(Calendar.MONTH);
return (endYear - startYear) * 12 + (endMonth - startMonth) + 1;
}
/**
* 计算两个日期之间的年份差
*
* @param startDate 开始日期
* @param endDate 结束日期
* @return 年份差
*/
private static int getYearDiff(Date startDate, Date endDate) {
Calendar startCalendar = Calendar.getInstance();
startCalendar.setTime(startDate);
int startYear = startCalendar.get(Calendar.YEAR);
Calendar endCalendar = Calendar.getInstance();
endCalendar.setTime(endDate);
int endYear = endCalendar.get(Calendar.YEAR);
return endYear - startYear + 1;
}
}
/**
* 租金计划
*/
class RentPlan {
// 收款日期
private Date paymentDate;
// 租期起始日期
private Date startDate;
// 租期终止日期
private Date endDate;
// 租期单价
private BigDecimal unitPrice;
// 租期(月数)
private int term;
// 租金
private BigDecimal rent;
public RentPlan(Date paymentDate, Date startDate, Date endDate, BigDecimal unitPrice, int term, BigDecimal rent) {
this.paymentDate = paymentDate;
this.startDate = startDate;
this.endDate = endDate;
this.unitPrice = unitPrice;
this.term = term;
this.rent = rent;
}
public Date getPaymentDate() {
return paymentDate;
}
public void setPaymentDate(Date paymentDate) {
this.paymentDate = paymentDate;
}
public Date getStartDate() {
return startDate;
}
public void setStartDate(Date startDate) {
this.startDate = startDate;
}
public Date getEndDate() {
return endDate;
}
public void setEndDate(Date endDate) {
this.endDate = endDate;
}
public BigDecimal getUnitPrice() {
return unitPrice;
}
public void setUnitPrice(BigDecimal unitPrice) {
this.unitPrice = unitPrice;
}
public int getTerm() {
return term;
}
public void setTerm(int term) {
this.term = term;
}
public BigDecimal getRent() {
return rent;
}
public void setRent(BigDecimal rent) {
this.rent = rent;
}
}
```
以上代码中,我使用了BigDecimal来处理货币计算,避免了浮点数计算精度问题。在计算租金计划列表时,我使用了一个循环,每次计算一个租期的租金,并且根据当前日期和当前租期单价计算下一个租期的租金。在计算租期单价时,我根据合同的免租期进行了特殊处理。在计算收款日期时,我根据租期终止日期往前推一个月,并且加上一天,以确保收款日期在租期结束后。在计算递增周期内的租期单价时,我使用了取模运算来判断是否达到一个递增周期。在计算递增后的租期单价时,我使用了BigDecimal的乘法和除法运算,并且使用了setScale方法来设置小数点后的位数,并且使用了RoundingMode.HALF_UP来进行四舍五入。在输出租金计划列表时,我使用了SimpleDateFormat来将日期格式化为字符串。
阅读全文