合同开始日期:2023-01-01,结束日期:2026-01-01,免租起始期:2023-01-01,免租终止日期:2023-01-31,收款方式为按3个月收一次,提前收款期为3个月,基本租期1年,月租单价500,超过基本租期后按2年一个周期递增,以基本租期月租金为基础复合按年递增率为6%,按java7的语法,产生 合同期内每月含收款日期、租期的租金计划列表并配上代码说明。
时间: 2023-12-22 21:06:40 浏览: 16
好的,根据您提供的信息,我可以给出以下Java代码实现:
```java
import java.time.LocalDate;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.List;
public class RentSchedule {
private LocalDate startDate; // 合同开始日期
private LocalDate endDate; // 合同结束日期
private LocalDate rentFreeStartDate; // 免租起始期
private LocalDate rentFreeEndDate; // 免租终止日期
private int rentPaymentInterval; // 收款间隔,单位:月
private int rentIncreaseInterval; // 租金递增周期,单位:年
private double rentBasePrice; // 基本租金单价
private double rentIncreaseRate; // 租金递增率
public RentSchedule(LocalDate startDate, LocalDate endDate, LocalDate rentFreeStartDate, LocalDate rentFreeEndDate,
int rentPaymentInterval, int rentIncreaseInterval, double rentBasePrice, double rentIncreaseRate) {
this.startDate = startDate;
this.endDate = endDate;
this.rentFreeStartDate = rentFreeStartDate;
this.rentFreeEndDate = rentFreeEndDate;
this.rentPaymentInterval = rentPaymentInterval;
this.rentIncreaseInterval = rentIncreaseInterval;
this.rentBasePrice = rentBasePrice;
this.rentIncreaseRate = rentIncreaseRate;
}
public List<RentPlan> generateRentSchedule() {
List<RentPlan> rentPlanList = new ArrayList<>();
LocalDate currentDate = startDate;
while (currentDate.isBefore(endDate) || currentDate.isEqual(endDate)) {
if (currentDate.isBefore(rentFreeEndDate) || currentDate.isEqual(rentFreeEndDate)
|| currentDate.isAfter(rentFreeStartDate) || currentDate.isEqual(rentFreeStartDate)) {
// 在免租期内
rentPlanList.add(new RentPlan(currentDate, 0));
} else {
// 非免租期
double rentPrice = rentBasePrice;
if (ChronoUnit.MONTHS.between(startDate, currentDate) % (12 * rentIncreaseInterval) == 0) {
// 基本租期结束后,每2年按租金递增率递增
int rentIncreaseTimes = (int) (ChronoUnit.MONTHS.between(startDate, currentDate) / (12 * rentIncreaseInterval));
rentPrice = rentBasePrice * Math.pow(1 + rentIncreaseRate, rentIncreaseTimes);
}
rentPlanList.add(new RentPlan(currentDate, rentPrice));
}
currentDate = currentDate.plusMonths(rentPaymentInterval);
}
return rentPlanList;
}
public static void main(String[] args) {
RentSchedule rentSchedule = new RentSchedule(
LocalDate.of(2023, 1, 1), // 合同开始日期
LocalDate.of(2026, 1, 1), // 合同结束日期
LocalDate.of(2023, 1, 1), // 免租起始期
LocalDate.of(2023, 1, 31), // 免租终止日期
3, // 收款间隔,单位:月
2, // 租金递增周期,单位:年
500, // 基本租金单价
0.06 // 租金递增率
);
List<RentPlan> rentScheduleList = rentSchedule.generateRentSchedule();
for (RentPlan rentPlan : rentScheduleList) {
System.out.println("收款日期:" + rentPlan.getPaymentDate() + ",租期:" + rentPaymentInterval + "个月,租金:" + rentPlan.getRentPrice() + "元");
}
}
}
class RentPlan {
private LocalDate paymentDate; // 收款日期
private double rentPrice; // 租金
public RentPlan(LocalDate paymentDate, double rentPrice) {
this.paymentDate = paymentDate;
this.rentPrice = rentPrice;
}
public LocalDate getPaymentDate() {
return paymentDate;
}
public double getRentPrice() {
return rentPrice;
}
}
```
代码说明如下:
- `RentSchedule`类表示租金计划,包含了合同开始日期、结束日期、免租期起始日期、免租期终止日期、收款间隔、租金递增周期、基本租金单价、租金递增率等属性;
- `generateRentSchedule()`方法用于生成租金计划,返回一个`RentPlan`对象的列表;
- `RentPlan`类表示租金计划中的一条租金记录,包含了收款日期和租金金额两个属性;
- `main()`方法中创建了一个`RentSchedule`对象,并调用`generateRentSchedule()`方法生成租金计划,最后输出租金计划中每一条租金记录的收款日期、租期和租金金额。
注意,这段代码中的租金递增率为0.06,即6%。如果需要使用小数表示的百分数,可以将租金递增率改为0.06。