是的

时间: 2024-02-17 10:02:36 浏览: 29
好的,以下是按照您提供的需求编写的Java 7示例代码: ``` import java.time.LocalDate; import java.time.temporal.ChronoUnit; import java.util.ArrayList; import java.util.List; public class RentContract { private LocalDate startDate; private LocalDate endDate; private LocalDate rentFreeStartDate; private LocalDate rentFreeEndDate; private double area; private double unitPrice; private int basePeriod; private int increasePeriod; private double increaseRate; public RentContract(LocalDate startDate, LocalDate endDate, LocalDate rentFreeStartDate, LocalDate rentFreeEndDate, double area, double unitPrice, int basePeriod, int increasePeriod, double increaseRate) { this.startDate = startDate; this.endDate = endDate; this.rentFreeStartDate = rentFreeStartDate; this.rentFreeEndDate = rentFreeEndDate; this.area = area; this.unitPrice = unitPrice; this.basePeriod = basePeriod; this.increasePeriod = increasePeriod; this.increaseRate = increaseRate; } public List<RentRecord> calculateRentRecords() { List<RentRecord> records = new ArrayList<>(); LocalDate currentDate = startDate; while (currentDate.isBefore(endDate)) { if (currentDate.isBefore(rentFreeEndDate)) { records.add(new RentRecord(currentDate, null, null, 0)); currentDate = rentFreeEndDate.plusDays(1); } else { LocalDate periodStart = currentDate; LocalDate periodEnd = periodStart.plusMonths(basePeriod).minusDays(1); if (periodEnd.isAfter(endDate)) { periodEnd = endDate; } double periodPrice = unitPrice; int periodMonthCount = (int) ChronoUnit.MONTHS.between(periodStart, periodEnd) + 1; double periodRent = periodMonthCount * area * periodPrice; records.add(new RentRecord(currentDate, periodStart, periodEnd, periodRent)); currentDate = periodEnd.plusDays(1); while (currentDate.isBefore(endDate) && ChronoUnit.MONTHS.between(startDate, currentDate) % increasePeriod == 0) { periodPrice *= (1 + increaseRate); periodStart = currentDate; periodEnd = periodStart.plusMonths(increasePeriod).minusDays(1); if (periodEnd.isAfter(endDate)) { periodEnd = endDate; } periodMonthCount = (int) ChronoUnit.MONTHS.between(periodStart, periodEnd) + 1; periodRent = periodMonthCount * area * periodPrice; records.add(new RentRecord(currentDate, periodStart, periodEnd, periodRent)); currentDate = periodEnd.plusDays(1); } } } return records; } public static void main(String[] args) { RentContract contract = new RentContract( LocalDate.of(2023, 1, 1), LocalDate.of(2026, 1, 1), LocalDate.of(2023, 1, 1), LocalDate.of(2023, 1, 31), 100, 20, 12, 12, 0.06 ); List<RentRecord> records = contract.calculateRentRecords(); System.out.println("收款日期\t\t租期起始日期\t租期终止日期\t\t租期单价\t租期(月数)\t租金"); for (RentRecord record : records) { System.out.println(record.getDueDate() + "\t" + record.getPeriodStartDate() + "\t" + record.getPeriodEndDate() + "\t" + contract.unitPrice + "\t" + (int) ChronoUnit.MONTHS.between(record.getPeriodStartDate(), record.getPeriodEndDate()) + "\t\t" + record.getRent()); } } } class RentRecord { private LocalDate dueDate; private LocalDate periodStartDate; private LocalDate periodEndDate; private double rent; public RentRecord(LocalDate dueDate, LocalDate periodStartDate, LocalDate periodEndDate, double rent) { this.dueDate = dueDate; this.periodStartDate = periodStartDate; this.periodEndDate = periodEndDate; this.rent = rent; } public LocalDate getDueDate() { return dueDate; } public LocalDate getPeriodStartDate() { return periodStartDate; } public LocalDate getPeriodEndDate() { return periodEndDate; } public double getRent() { return rent; } } ``` 上面的代码中,`RentContract`类表示租赁合同,包含合同起始日期、合同结束日期、免租起始日期、免租结束日期、计费面积、月租单价、基本租期(月数)、递增周期(月数)和递增率等属性。`calculateRentRecords`方法用于计算合同期内的租金计划列表,返回一个`RentRecord`对象的列表。`RentRecord`类表示租金记录,包含收款日期、租期起始日期、租期终止日期和租金等属性。 在`main`方法中,我们创建了一个租赁合同对象,并调用`calculateRentRecords`方法计算租金计划列表。最后,我们遍历租金计划列表,依次输出每条记录的收款日期、租期起始日期、租期终止日期、租期单价、租期(月数)和租金。 请注意,由于您没有提供具体的计算方式,因此我们在示例代码中采用了一个可能的计算方式,即每3个月计算一次租金并按3个月收一次款。如果您需要更改计算方式,请修改`calculateRentRecords`方法中的代码。

相关推荐

最新推荐

recommend-type

python2练习题——编写函数,输入数字,判断是否是素数

(2)初等数学基本定理:任一大于1的自然数,要么本身是质数,要么可以分解为几个质数之积,且这种分解是唯一的。 (3)质数的个数是无限的。 (4)质数的个数公式 是不减函数。 (5)若n为正整数,在 到 之间至少有...
recommend-type

Python计算指定日期是今年的第几天(三种方法)

主要介绍了Python三种方法计算指定日期是今年的第几天,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
recommend-type

java判断字符串是正整数的实例

今天小编就为大家分享一篇java判断字符串是正整数的实例,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
recommend-type

oracle中schema指的是什么意思

看来有的人还是对schema的真正含义不太理解,现在我再次整理了一下,需要的朋友参考下
recommend-type

网卡驱动问题(主要是无线网卡),设备管理器里面代码错误号是56

该文件是本人全部尝试过的解决方法(没有试过硬件损坏的情况),最终解决了错误代码56的情况,主要包含了5种方法,注意,此5中方法顺序不作任何要求,希望能帮助各位解决问题。
recommend-type

zigbee-cluster-library-specification

最新的zigbee-cluster-library-specification说明文档。
recommend-type

管理建模和仿真的文件

管理Boualem Benatallah引用此版本:布阿利姆·贝纳塔拉。管理建模和仿真。约瑟夫-傅立叶大学-格勒诺布尔第一大学,1996年。法语。NNT:电话:00345357HAL ID:电话:00345357https://theses.hal.science/tel-003453572008年12月9日提交HAL是一个多学科的开放存取档案馆,用于存放和传播科学研究论文,无论它们是否被公开。论文可以来自法国或国外的教学和研究机构,也可以来自公共或私人研究中心。L’archive ouverte pluridisciplinaire
recommend-type

MATLAB柱状图在信号处理中的应用:可视化信号特征和频谱分析

![matlab画柱状图](https://img-blog.csdnimg.cn/3f32348f1c9c4481a6f5931993732f97.png) # 1. MATLAB柱状图概述** MATLAB柱状图是一种图形化工具,用于可视化数据中不同类别或组的分布情况。它通过绘制垂直条形来表示每个类别或组中的数据值。柱状图在信号处理中广泛用于可视化信号特征和进行频谱分析。 柱状图的优点在于其简单易懂,能够直观地展示数据分布。在信号处理中,柱状图可以帮助工程师识别信号中的模式、趋势和异常情况,从而为信号分析和处理提供有价值的见解。 # 2. 柱状图在信号处理中的应用 柱状图在信号处理
recommend-type

用Spring boot和vue写一个登录注册界面

好的,这是一个比较常见的技术问题,我可以为您提供一些参考资料和思路。首先,您可以使用Spring Boot作为后端框架来处理用户认证和注册的逻辑,比如使用Spring Security实现用户登录认证。同时,您还需要设计相应的数据模型和数据库表结构来存储用户信息。在前端方面,您可以使用Vue.js作为框架来构建登录注册页面,使用Axios来发起API请求并和后端进行交互。当然,在实现过程中,还需要考虑一些具体细节,比如数据校验、安全性和用户体验等方面。希望这些信息能够帮助到您。
recommend-type

JSBSim Reference Manual

JSBSim参考手册,其中包含JSBSim简介,JSBSim配置文件xml的编写语法,编程手册以及一些应用实例等。其中有部分内容还没有写完,估计有生之年很难看到完整版了,但是内容还是很有参考价值的。