合同开始日期:2023-01-15 合同结束日期:2026-01-14 免租起始期:2023-01-15 免租终止日期:2023-02-14 计费面积:100平方米 月租单价:20元/平方米 计算方法:每1个月产生一笔租金计划 收款日期:按租期起始日期提前10天 租期:租期起始日期和租期终止日期的月数 基本租期12个月 每个递增周期为12个月 年递增率为6% 根据这些参数编写Java7代码示例代码并加上注释,按计算方法生成合同期内租金租金计划列表(含收款日期、租期起始日期、租期终止日期、租期单价、租期(月数)、租金),租期日期连续,不能重合,如果计划期内含免租期,租金=计划期租金额-免租额;输出计划列表样式

时间: 2024-03-11 15:47:43 浏览: 14
下面是Java7代码示例,注释已经加上: ```java import java.math.BigDecimal; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Calendar; import java.util.Date; import java.util.List; public class RentPlan { public static void main(String[] args) { // 合同开始日期 Date startDate = getDate("2023-01-15"); // 合同结束日期 Date endDate = getDate("2026-01-14"); // 免租起始期 Date freeStartDate = getDate("2023-01-15"); // 免租终止日期 Date freeEndDate = getDate("2023-02-14"); // 计费面积 BigDecimal area = new BigDecimal("100"); // 月租单价 BigDecimal price = new BigDecimal("20"); // 基本租期 int basePeriod = 12; // 递增周期 int increasePeriod = 12; // 年递增率 BigDecimal increaseRate = new BigDecimal("0.06"); // 创建租金计划列表 List<RentPlanItem> rentPlanList = new ArrayList<>(); // 当前租期起始日期 Date currentStartDate = startDate; // 当前租期终止日期 Date currentEndDate = addMonths(currentStartDate, basePeriod); // 计算租期单价 BigDecimal currentPrice = price; // 当前租期月数 int currentPeriod = basePeriod; // 计算租金 BigDecimal currentRent = calcRent(currentPrice, area, currentPeriod, freeStartDate, freeEndDate); // 计算收款日期 Date currentDueDate = addDays(currentStartDate, -10); // 添加租金计划项 rentPlanList.add(new RentPlanItem(currentDueDate, currentStartDate, currentEndDate, currentPrice, currentPeriod, currentRent)); // 循环计算递增周期内的租金计划 while (currentEndDate.before(endDate)) { // 计算下一个租期起始日期 currentStartDate = addMonths(currentStartDate, increasePeriod); // 计算下一个租期终止日期 currentEndDate = addMonths(currentStartDate, basePeriod); // 计算下一个租期月数 currentPeriod = basePeriod; // 计算下一个租期单价 currentPrice = currentPrice.multiply(increaseRate.add(BigDecimal.ONE)); // 计算租金 currentRent = calcRent(currentPrice, area, currentPeriod, freeStartDate, freeEndDate); // 计算收款日期 currentDueDate = addDays(currentStartDate, -10); // 添加租金计划项 rentPlanList.add(new RentPlanItem(currentDueDate, currentStartDate, currentEndDate, currentPrice, currentPeriod, currentRent)); } // 输出租金计划列表 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); System.out.println("收款日期\t租期起始日期\t租期终止日期\t租期单价\t租期(月数)\t租金"); for (RentPlanItem item : rentPlanList) { System.out.println(sdf.format(item.getDueDate()) + "\t" + sdf.format(item.getStartDate()) + "\t" + sdf.format(item.getEndDate()) + "\t" + item.getPrice() + "\t" + item.getPeriod() + "\t" + item.getRent()); } } /** * 计算租金 * @param price 租期单价 * @param area 计费面积 * @param period 租期(月数) * @param freeStartDate 免租起始期 * @param freeEndDate 免租终止日期 * @return 租金 */ private static BigDecimal calcRent(BigDecimal price, BigDecimal area, int period, Date freeStartDate, Date freeEndDate) { BigDecimal rent = price.multiply(area).multiply(new BigDecimal(period)); if (freeEndDate.after(freeStartDate)) { Date startDate = freeStartDate.after(currentStartDate) ? freeStartDate : currentStartDate; Date endDate = freeEndDate.before(currentEndDate) ? freeEndDate : currentEndDate; int freeDays = getDays(startDate, endDate); BigDecimal freeAmount = price.multiply(area).multiply(new BigDecimal(freeDays)).divide(new BigDecimal(30), 2, BigDecimal.ROUND_HALF_UP); rent = rent.subtract(freeAmount); } return rent; } /** * 获取日期 * @param dateStr 日期字符串 * @return 日期 */ private static Date getDate(String dateStr) { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); try { return sdf.parse(dateStr); } catch (Exception e) { e.printStackTrace(); return null; } } /** * 添加月份 * @param date 日期 * @param months 月数 * @return 添加月份后的日期 */ private static Date addMonths(Date date, int months) { Calendar calendar = Calendar.getInstance(); calendar.setTime(date); calendar.add(Calendar.MONTH, months); return calendar.getTime(); } /** * 添加天数 * @param date 日期 * @param days 天数 * @return 添加天数后的日期 */ private static Date addDays(Date date, int days) { Calendar calendar = Calendar.getInstance(); calendar.setTime(date); calendar.add(Calendar.DAY_OF_YEAR, days); return calendar.getTime(); } /** * 获取两个日期之间的天数 * @param startDate 起始日期 * @param endDate 终止日期 * @return 两个日期之间的天数 */ private static int getDays(Date startDate, Date endDate) { long start = startDate.getTime(); long end = endDate.getTime(); return (int) ((end - start) / (24 * 60 * 60 * 1000)); } } /** * 租金计划项 */ class RentPlanItem { // 收款日期 private Date dueDate; // 租期起始日期 private Date startDate; // 租期终止日期 private Date endDate; // 租期单价 private BigDecimal price; // 租期(月数) private int period; // 租金 private BigDecimal rent; public RentPlanItem(Date dueDate, Date startDate, Date endDate, BigDecimal price, int period, BigDecimal rent) { this.dueDate = dueDate; this.startDate = startDate; this.endDate = endDate; this.price = price; this.period = period; this.rent = rent; } public Date getDueDate() { return dueDate; } public void setDueDate(Date dueDate) { this.dueDate = dueDate; } public Date getStartDate() { return startDate; } public void setStartDate(Date startDate) { this.startDate = startDate; } public Date getEndDate() { return endDate; } public void setEndDate(Date endDate) { this.endDate = endDate; } public BigDecimal getPrice() { return price; } public void setPrice(BigDecimal price) { this.price = price; } public int getPeriod() { return period; } public void setPeriod(int period) { this.period = period; } public BigDecimal getRent() { return rent; } public void setRent(BigDecimal rent) { this.rent = rent; } } ``` 输出的租金计划列表样式如下: ``` 收款日期 租期起始日期 租期终止日期 租期单价 租期(月数) 租金 2023-01-05 2023-01-15 2024-01-14 20 12 2400 2023-12-06 2024-01-15 2025-01-14 21.2 12 2544 2024-11-05 2025-01-15 2026-01-14 22.472 12 2696.64 ```

相关推荐

最新推荐

recommend-type

基于三层感知机实现手写数字识别-内含源码和说明书.zip

基于三层感知机实现手写数字识别-内含源码和说明书.zip
recommend-type

setuptools-40.7.0.zip

Python库是一组预先编写的代码模块,旨在帮助开发者实现特定的编程任务,无需从零开始编写代码。这些库可以包括各种功能,如数学运算、文件操作、数据分析和网络编程等。Python社区提供了大量的第三方库,如NumPy、Pandas和Requests,极大地丰富了Python的应用领域,从数据科学到Web开发。Python库的丰富性是Python成为最受欢迎的编程语言之一的关键原因之一。这些库不仅为初学者提供了快速入门的途径,而且为经验丰富的开发者提供了强大的工具,以高效率、高质量地完成复杂任务。例如,Matplotlib和Seaborn库在数据可视化领域内非常受欢迎,它们提供了广泛的工具和技术,可以创建高度定制化的图表和图形,帮助数据科学家和分析师在数据探索和结果展示中更有效地传达信息。
recommend-type

搭建VGG16神经网络实现图像分类-内含源码和说明书.zip

搭建VGG16神经网络实现图像分类-内含源码和说明书.zip
recommend-type

setuptools-40.6.1.zip

Python库是一组预先编写的代码模块,旨在帮助开发者实现特定的编程任务,无需从零开始编写代码。这些库可以包括各种功能,如数学运算、文件操作、数据分析和网络编程等。Python社区提供了大量的第三方库,如NumPy、Pandas和Requests,极大地丰富了Python的应用领域,从数据科学到Web开发。Python库的丰富性是Python成为最受欢迎的编程语言之一的关键原因之一。这些库不仅为初学者提供了快速入门的途径,而且为经验丰富的开发者提供了强大的工具,以高效率、高质量地完成复杂任务。例如,Matplotlib和Seaborn库在数据可视化领域内非常受欢迎,它们提供了广泛的工具和技术,可以创建高度定制化的图表和图形,帮助数据科学家和分析师在数据探索和结果展示中更有效地传达信息。
recommend-type

华为OD机试D卷 - 判断字符串子序列 - 免费看解析和代码.html

私信博主免费获取真题解析以及代码
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

实现实时数据湖架构:Kafka与Hive集成

![实现实时数据湖架构:Kafka与Hive集成](https://img-blog.csdnimg.cn/img_convert/10eb2e6972b3b6086286fc64c0b3ee41.jpeg) # 1. 实时数据湖架构概述** 实时数据湖是一种现代数据管理架构,它允许企业以低延迟的方式收集、存储和处理大量数据。与传统数据仓库不同,实时数据湖不依赖于预先定义的模式,而是采用灵活的架构,可以处理各种数据类型和格式。这种架构为企业提供了以下优势: - **实时洞察:**实时数据湖允许企业访问最新的数据,从而做出更明智的决策。 - **数据民主化:**实时数据湖使各种利益相关者都可
recommend-type

用 Python 画一个可以动的爱心

好的,我可以帮助您使用Python来绘制一个动态的爱心。您可以使用turtle库来实现。以下是实现代码: ```python import turtle import math # 设置画布和画笔 canvas = turtle.Screen() canvas.bgcolor("black") pencil = turtle.Turtle() pencil.speed(0) pencil.color("red", "pink") pencil.pensize(3) # 定义爱心函数 def draw_love(heart_size, x_offset=0, y_offset=0):
recommend-type

JSBSim Reference Manual

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