合同开始日期:2023-01-01,结束日期:2026-01-01,免租起始期:2023-01-01,免租终止日期:023-01-31,收款方式为按3个月收一次,提前收款期为3个月,基本租期1年,月租单价500,超过基本租期后按2年一个周期递增,递增率为6%,按java7产生合同期内含收款日期、租期、租金的计划列表,配上代码说明
时间: 2023-12-22 11:06:41 浏览: 90
基于java开发房屋租赁系统源码,供参考使用
好的,根据您的要求,我来为您生成合同期内含收款日期、租期、租金的计划列表,并配上代码说明。以下是代码实现:
```java
import java.time.LocalDate;
import java.time.Period;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.List;
public class Contract {
private LocalDate startDate; // 合同开始日期
private LocalDate endDate; // 合同结束日期
private LocalDate rentFreeStartDate; // 免租起始期
private LocalDate rentFreeEndDate; // 免租终止日期
private int rentPaymentPeriod; // 收款周期,单位为月
private int advancePaymentPeriod; // 提前收款期,单位为月
private int baseLeasePeriod; // 基本租期,单位为年
private double baseMonthlyRent; // 基本月租金
private double incrementRate; // 递增率
public Contract(LocalDate startDate, LocalDate endDate, LocalDate rentFreeStartDate, LocalDate rentFreeEndDate,
int rentPaymentPeriod, int advancePaymentPeriod, int baseLeasePeriod, double baseMonthlyRent,
double incrementRate) {
this.startDate = startDate;
this.endDate = endDate;
this.rentFreeStartDate = rentFreeStartDate;
this.rentFreeEndDate = rentFreeEndDate;
this.rentPaymentPeriod = rentPaymentPeriod;
this.advancePaymentPeriod = advancePaymentPeriod;
this.baseLeasePeriod = baseLeasePeriod;
this.baseMonthlyRent = baseMonthlyRent;
this.incrementRate = incrementRate;
}
public List<PaymentPlan> generatePaymentPlan() {
List<PaymentPlan> paymentPlanList = new ArrayList<>();
LocalDate paymentDate = startDate;
// 计算基本租期内的租金
for (int i = 0; i < baseLeasePeriod * 12; i += rentPaymentPeriod) {
// 判断是否在免租期内
if (paymentDate.isBefore(rentFreeStartDate) || paymentDate.isAfter(rentFreeEndDate)) {
double monthlyRent = baseMonthlyRent * Math.pow(1 + incrementRate / 100, i / 12);
paymentPlanList.add(new PaymentPlan(paymentDate, rentPaymentPeriod, monthlyRent));
}
paymentDate = paymentDate.plusMonths(rentPaymentPeriod);
}
// 计算递增租期内的租金
while (paymentDate.isBefore(endDate)) {
int remainingMonths = (int) ChronoUnit.MONTHS.between(paymentDate, endDate);
int currentLeasePeriod = (int) Math.ceil((double) remainingMonths / (12 * 2)) * 2;
int currentRentPaymentPeriod = Math.min(currentLeasePeriod * 12, rentPaymentPeriod);
double monthlyRent = baseMonthlyRent * Math.pow(1 + incrementRate / 100, baseLeasePeriod)
* Math.pow(1 + incrementRate / 100, (paymentDate.getYear() - startDate.getYear()) * 12)
* Math.pow(1 + incrementRate / 100, (paymentDate.getMonthValue() - startDate.getMonthValue()));
paymentPlanList.add(new PaymentPlan(paymentDate, currentRentPaymentPeriod, monthlyRent));
paymentDate = paymentDate.plusMonths(currentRentPaymentPeriod);
}
return paymentPlanList;
}
public static void main(String[] args) {
Contract contract = new Contract(
LocalDate.of(2023, 1, 1),
LocalDate.of(2026, 1, 1),
LocalDate.of(2023, 1, 1),
LocalDate.of(2023, 1, 31),
3,
3,
1,
500,
6
);
List<PaymentPlan> paymentPlanList = contract.generatePaymentPlan();
// 打印每一笔租金的计划
for (PaymentPlan paymentPlan : paymentPlanList) {
System.out.println(paymentPlan.getPaymentDate() + " " + paymentPlan.getLeasePeriod()
+ " months " + paymentPlan.getMonthlyRent() + " RMB/month");
}
}
}
class PaymentPlan {
private LocalDate paymentDate; // 收款日期
private int leasePeriod; // 租期,单位为月
private double monthlyRent; // 月租金
public PaymentPlan(LocalDate paymentDate, int leasePeriod, double monthlyRent) {
this.paymentDate = paymentDate;
this.leasePeriod = leasePeriod;
this.monthlyRent = monthlyRent;
}
public LocalDate getPaymentDate() {
return paymentDate;
}
public int getLeasePeriod() {
return leasePeriod;
}
public double getMonthlyRent() {
return monthlyRent;
}
}
```
代码中,`Contract` 类表示合同,包含了合同的各项信息,如合同开始日期、结束日期、免租起始期、免租终止日期、收款周期、提前收款期、基本租期、基本月租金、递增率等。`generatePaymentPlan` 方法根据合同信息生成每一笔租金的计划,返回一个 `List`,其中每个元素是一个 `PaymentPlan` 对象,表示一笔租金的计划,包含了收款日期、租期、月租金等信息。
在 `main` 方法中,我们创建了一个 `Contract` 对象,并调用它的 `generatePaymentPlan` 方法生成租金计划。最后,我们遍历租金计划列表,打印每一笔租金的计划。
阅读全文