合同开始日期:2023-01-01,结束日期:2026-01-01,免租起始期:2023-01-01,免租终止日期:023-01-31,收款方式为按3个月收一次,提前收款期为3个月,基本租期1年,月租单价500,超过基本租期后按2年一个周期递增,递增率为6%,按java7产生合同期内含收款 日期、租期起始日期、租期终止日期、租金的计划列表,配上代码说明
时间: 2023-12-23 08:01:54 浏览: 87
好的,根据您的要求,我可以帮您生成合同期内的含收款日期、租期起始日期、租期终止日期、租金的计划列表。以下是代码实现:
```java
import java.time.LocalDate;
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 paymentPeriod = 3; // 收款周期(月)
private int advancePaymentPeriod = 3; // 提前收款期(月)
private int baseLeasePeriod = 12; // 基本租期(月)
private double monthlyRent = 500; // 月租单价(元)
private double incrementRate = 0.06; // 递增率
public Contract(LocalDate startDate, LocalDate endDate, LocalDate rentFreeStartDate, LocalDate rentFreeEndDate) {
this.startDate = startDate;
this.endDate = endDate;
this.rentFreeStartDate = rentFreeStartDate;
this.rentFreeEndDate = rentFreeEndDate;
}
public List<PaymentPlan> generatePaymentPlans() {
List<PaymentPlan> paymentPlans = new ArrayList<>();
LocalDate currentDate = startDate;
LocalDate lastPaymentDate = rentFreeEndDate.plusMonths(1); // 上一次收款日期
int currentPeriod = 1; // 当前周期
double currentRent = monthlyRent; // 当前租金
while (currentDate.isBefore(endDate)) {
if (currentDate.isAfter(rentFreeEndDate) && currentDate.getMonthValue() % paymentPeriod == 1) {
// 到了每个季度的第一个月,需要收租金
LocalDate paymentDate = currentDate.plusMonths(advancePaymentPeriod);
long daysBetween = ChronoUnit.DAYS.between(lastPaymentDate, paymentDate);
double rent = currentRent * (1 + incrementRate * (currentPeriod - 1) / 2);
PaymentPlan paymentPlan = new PaymentPlan(paymentDate, lastPaymentDate.plusDays(daysBetween / 2), paymentDate.plusDays(daysBetween / 2).minusDays(1), rent);
paymentPlans.add(paymentPlan);
lastPaymentDate = paymentDate;
currentPeriod++;
if (currentPeriod > baseLeasePeriod / paymentPeriod) {
currentRent *= (1 + incrementRate);
}
}
currentDate = currentDate.plusDays(1);
}
return paymentPlans;
}
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));
List<PaymentPlan> paymentPlans = contract.generatePaymentPlans();
for (PaymentPlan paymentPlan : paymentPlans) {
System.out.println(paymentPlan);
}
}
}
class PaymentPlan {
private LocalDate paymentDate; // 收款日期
private LocalDate leaseStartDate; // 租期起始日期
private LocalDate leaseEndDate; // 租期终止日期
private double rent; // 租金
public PaymentPlan(LocalDate paymentDate, LocalDate leaseStartDate, LocalDate leaseEndDate, double rent) {
this.paymentDate = paymentDate;
this.leaseStartDate = leaseStartDate;
this.leaseEndDate = leaseEndDate;
this.rent = rent;
}
public LocalDate getPaymentDate() {
return paymentDate;
}
public void setPaymentDate(LocalDate paymentDate) {
this.paymentDate = paymentDate;
}
public LocalDate getLeaseStartDate() {
return leaseStartDate;
}
public void setLeaseStartDate(LocalDate leaseStartDate) {
this.leaseStartDate = leaseStartDate;
}
public LocalDate getLeaseEndDate() {
return leaseEndDate;
}
public void setLeaseEndDate(LocalDate leaseEndDate) {
this.leaseEndDate = leaseEndDate;
}
public double getRent() {
return rent;
}
public void setRent(double rent) {
this.rent = rent;
}
@Override
public String toString() {
return "PaymentPlan{" +
"paymentDate=" + paymentDate +
", leaseStartDate=" + leaseStartDate +
", leaseEndDate=" + leaseEndDate +
", rent=" + rent +
'}';
}
}
```
在这个代码中,我们定义了一个 `Contract` 类,它包含了合同的开始日期、结束日期、免租起始期、免租终止日期等属性。我们还定义了一个 `PaymentPlan` 类,它表示了一个收款计划,包含了收款日期、租期起始日期、租期终止日期、租金等属性。
在 `Contract` 类中,我们实现了一个 `generatePaymentPlans` 方法,用于生成合同期内的收款计划。我们首先定义了当前日期 `currentDate`,并初始化为合同开始日期。然后我们定义了一个 `lastPaymentDate` 变量,表示上一次收款日期,初始化为免租终止日期加上一个月。我们还定义了一个 `currentPeriod` 变量,表示当前周期,初始化为 1。定义了一个 `currentRent` 变量,表示当前租金,初始化为月租单价。然后我们进入了一个循环,遍历合同期内的每一天。如果当前日期在免租期之后,并且到了每个季度的第一个月,我们就需要收租金了。我们计算出收款日期 `paymentDate`,并计算出上一次收款日期到当前收款日期之间的天数 `daysBetween`。然后我们根据当前周期计算出当前租金 `rent`,如果当前周期超过了基本租期,就需要按照递增率递增租金。最后我们创建一个 `PaymentPlan` 对象,并把它加入到收款计划列表中。然后我们更新上一次收款日期、当前周期等变量,继续遍历下一天。最后我们返回收款计划列表。
在 `main` 方法中,我们创建了一个 `Contract` 对象,并调用 `generatePaymentPlans` 方法生成收款计划列表。然后遍历收款计划列表,打印出每个收款计划的详细信息。
希望这个代码能够满足您的需求。如果您有任何问题,请随时问我。
阅读全文