合同开始日期:2023-01-01,结束日期:2026-01-01,免租起始期:2023-01-01,免租终止日期:023-01-31,不足月按月算,计费面积:100平方米,月租单价20/平方米,计算方式:每3月计算产生一条记录,收款方式为按3个月收一次,提前收款期为1个月,基本租期12月,超过基本租期后按12月为一个递增周期,每一递增周期内月租单价按上一周期内月租单价复合递增,年递增率为6%;按java7的语法:按计算方式循环产生合同期内含收款日期、租期起始日期、租期终止日期、租期单价、租期(月数)、租金的计划列表,生成一个完整示例和测试方法
时间: 2024-02-21 09:00:05 浏览: 168
好的,根据您的需求,我已经编写了一个示例和测试方法,如下所示:
```
import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.List;
public class LeaseContract {
private static final BigDecimal UNIT_PRICE = new BigDecimal("20.00");
private static final BigDecimal INCREASE_RATE = new BigDecimal("0.06");
private static final int BASIC_TERM = 12;
private static final int INCREASE_TERM = 12;
private static final int CALCULATE_TERM = 3;
private static final int NOTICE_TERM = 1;
private static final LocalDate START_DATE = LocalDate.of(2023, 1, 1);
private static final LocalDate END_DATE = LocalDate.of(2026, 1, 1);
private static final LocalDate FREE_START_DATE = LocalDate.of(2023, 1, 1);
private static final LocalDate FREE_END_DATE = LocalDate.of(2023, 1, 31);
private static final int AREA = 100;
public static void main(String[] args) {
List<LeaseRecord> leaseRecords = generateLeaseRecords();
for (LeaseRecord leaseRecord : leaseRecords) {
System.out.println(leaseRecord);
}
}
private static List<LeaseRecord> generateLeaseRecords() {
List<LeaseRecord> leaseRecords = new ArrayList<>();
LocalDate currentDate = START_DATE;
int month = 0;
while (currentDate.isBefore(END_DATE)) {
BigDecimal unitPrice = calculateUnitPrice(currentDate);
int term = calculateTerm(currentDate);
BigDecimal rent = unitPrice.multiply(new BigDecimal(AREA)).multiply(new BigDecimal(term));
LeaseRecord leaseRecord = new LeaseRecord(currentDate.plusMonths(NOTICE_TERM), currentDate, currentDate.plusMonths(term), unitPrice, term, rent);
leaseRecords.add(leaseRecord);
currentDate = currentDate.plusMonths(term);
month += term;
}
return leaseRecords;
}
private static BigDecimal calculateUnitPrice(LocalDate date) {
int month = calculateMonth(date);
BigDecimal unitPrice = UNIT_PRICE;
for (int i = 0; i < month / INCREASE_TERM; i++) {
unitPrice = unitPrice.multiply(BigDecimal.ONE.add(INCREASE_RATE));
}
return unitPrice;
}
private static int calculateMonth(LocalDate date) {
return (int) ChronoUnit.MONTHS.between(START_DATE, date);
}
private static int calculateTerm(LocalDate date) {
int month = calculateMonth(date);
int term = BASIC_TERM;
if (month > BASIC_TERM) {
term += (month - BASIC_TERM) / INCREASE_TERM * BASIC_TERM;
}
LocalDate endDate = date.plusMonths(term);
if (endDate.isAfter(END_DATE)) {
term = (int) ChronoUnit.MONTHS.between(date, END_DATE);
}
return term;
}
private static class LeaseRecord {
private LocalDate paymentDate;
private LocalDate startDate;
private LocalDate endDate;
private BigDecimal unitPrice;
private int term;
private BigDecimal rent;
public LeaseRecord(LocalDate paymentDate, LocalDate startDate, LocalDate 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 LocalDate getPaymentDate() {
return paymentDate;
}
public LocalDate getStartDate() {
return startDate;
}
public LocalDate getEndDate() {
return endDate;
}
public BigDecimal getUnitPrice() {
return unitPrice;
}
public int getTerm() {
return term;
}
public BigDecimal getRent() {
return rent;
}
@Override
public String toString() {
return "LeaseRecord{" +
"paymentDate=" + paymentDate +
", startDate=" + startDate +
", endDate=" + endDate +
", unitPrice=" + unitPrice +
", term=" + term +
", rent=" + rent +
'}';
}
}
}
```
这个代码生成了一个租赁合同的计划列表,包括每次收款的日期、租期起始日期、租期终止日期、租期单价、租期(月数)和租金。您可以在`main`方法中直接运行测试,输出的结果将显示在控制台上。
阅读全文