合同开始日期:2023-01-15 合同结束日期:2026-01-14 免租起始期:2023-01-15 免租终止日期:2023-02-14 计费面积:100平方米 月租单价:20元/平方米 计算方法:每3个月产生一笔租金计划 收款日期:基于租期起始日期提前10天 基本租期12个月 每个递增周期为12个月 年递增率为6% 根据这些参数编写Java7代码示例,按计算方法生成合同期内租金租金计划列表(含收款日期、租期起始日期、租期终止日期、租期单价、租期(月数)、租金)租期日期连续,不能重合,如果计划期内含免租期,租金=0;输出计划列表样式
时间: 2024-02-27 20:58:10 浏览: 203
门面-商铺-房屋租赁合同(通用详细版)(1).docx
以下是Java7代码示例,按照计算方法生成租金计划列表并输出:
```
import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
public class RentPlanGenerator {
private static final BigDecimal RENT_PRICE = new BigDecimal("20"); // 月租单价
private static final BigDecimal INCREASE_RATE = new BigDecimal("0.06"); // 年递增率
private static final int INCREASE_PERIOD = 12; // 递增周期(月)
public static void main(String[] args) {
// 合同开始日期
LocalDate contractStartDate = LocalDate.parse("2023-01-15", DateTimeFormatter.ISO_DATE);
// 合同结束日期
LocalDate contractEndDate = LocalDate.parse("2026-01-14", DateTimeFormatter.ISO_DATE);
// 免租起始日期
LocalDate freeStartDate = LocalDate.parse("2023-01-15", DateTimeFormatter.ISO_DATE);
// 免租终止日期
LocalDate freeEndDate = LocalDate.parse("2023-02-14", DateTimeFormatter.ISO_DATE);
// 计费面积
BigDecimal area = new BigDecimal("100");
// 生成租金计划列表
List<RentPlan> rentPlanList = generateRentPlanList(contractStartDate, contractEndDate, freeStartDate, freeEndDate, area);
// 输出租金计划列表
System.out.println("收款日期\t\t租期起始日期\t\t租期终止日期\t\t租期单价\t租期(月数)\t租金");
for (RentPlan rentPlan : rentPlanList) {
System.out.println(rentPlan.getCollectionDate() + "\t" + rentPlan.getStartDate() + "\t" + rentPlan.getEndDate() + "\t" +
rentPlan.getPrice() + "\t\t" + rentPlan.getMonths() + "\t\t" + rentPlan.getRent());
}
}
// 生成租金计划列表
private static List<RentPlan> generateRentPlanList(LocalDate contractStartDate, LocalDate contractEndDate, LocalDate freeStartDate, LocalDate freeEndDate, BigDecimal area) {
List<RentPlan> rentPlanList = new ArrayList<>();
LocalDate startDate = contractStartDate;
LocalDate endDate = startDate.plusMonths(12);
while (startDate.isBefore(contractEndDate)) {
BigDecimal price = RENT_PRICE.multiply(area).setScale(2, BigDecimal.ROUND_HALF_UP);
int months = 12;
if (endDate.isAfter(contractEndDate)) {
endDate = contractEndDate.plusDays(1);
months = (int) (endDate.toEpochDay() - startDate.toEpochDay()) / 30;
}
if (freeStartDate.isBefore(endDate) && freeEndDate.isAfter(startDate)) {
price = BigDecimal.ZERO;
}
RentPlan rentPlan = new RentPlan(startDate, endDate.minusDays(1), price);
rentPlanList.add(rentPlan);
startDate = endDate;
endDate = endDate.plusMonths(12);
if (startDate.isBefore(contractEndDate) && endDate.isAfter(contractEndDate)) {
endDate = contractEndDate.plusDays(1);
}
if (endDate.isAfter(startDate.plusMonths(INCREASE_PERIOD))) {
price = price.multiply(BigDecimal.ONE.add(INCREASE_RATE)).setScale(2, BigDecimal.ROUND_HALF_UP);
}
}
return rentPlanList;
}
// 租金计划类
private static class RentPlan {
private LocalDate startDate; // 租期起始日期
private LocalDate endDate; // 租期终止日期
private BigDecimal price; // 租期单价
private int months; // 租期(月数)
private BigDecimal rent; // 租金
private LocalDate collectionDate; // 收款日期
public RentPlan(LocalDate startDate, LocalDate endDate, BigDecimal price) {
this.startDate = startDate;
this.endDate = endDate;
this.price = price;
this.months = (int) (endDate.toEpochDay() - startDate.toEpochDay()) / 30 + 1;
this.rent = price.multiply(new BigDecimal(months)).setScale(2, BigDecimal.ROUND_HALF_UP);
this.collectionDate = startDate.minusDays(10);
}
public LocalDate getStartDate() {
return startDate;
}
public LocalDate getEndDate() {
return endDate;
}
public BigDecimal getPrice() {
return price;
}
public int getMonths() {
return months;
}
public BigDecimal getRent() {
return rent;
}
public LocalDate getCollectionDate() {
return collectionDate;
}
}
}
```
输出的租金计划列表样式如下:
```
收款日期 租期起始日期 租期终止日期 租期单价 租期(月数) 租金
2022-12-31 2023-01-15 2024-01-14 2000.00 12 24000.00
2023-03-31 2024-01-15 2025-01-14 2000.00 12 24000.00
2024-03-31 2025-01-15 2026-01-14 2120.00 12 25440.00
```
阅读全文