package com.rental; /** * 测试类 TestCar:验证 Car 类的所有功能 * 包含:不同构造方法创建对象、显示信息、租车/还车状态切换及重复操作提示、 * 租金计算、非法日租金设置、静态总数统计 */ public class TestCar { public static void main(String[] args) { System.out.println("=== 车辆管理系统测试开始 ==="); // 1. 使用不同构造方法创建至少 3 个 Car 对象 Car car1 = new Car("京A·12345", "比亚迪", "汉EV", 500.0); Car car2 = new Car("沪B·67890", "特斯拉", "Model 3"); // 默认日租金 300.0 Car car3 = new Car("粤C·11111", "宝马", "X5", 800.0); // 2. 输出所有车辆信息 System.out.println("\n【所有车辆信息】"); car1.displayInfo(); System.out.println("---------------------"); car2.displayInfo(); System.out.println("---------------------"); car3.displayInfo(); System.out.println("---------------------"); // 3. 对 car1 进行租车/还车测试(覆盖正常和重复操作) System.out.println("【对 " + car1.getLicensePlate() + " 进行租车/还车测试】"); car1.rentCar(); // 首次租车(成功,无输出) car1.rentCar(); // 重复租车 → 输出提示 car1.returnCar(); // 还车(成功,无输出) car1.returnCar(); // 重复还车 → 输出提示 // 4. 计算租金 double rentFee = car1.calculateRent(5); System.out.println("租用 5 天总租金:" + rentFee + " 元"); // 5. 尝试设置非法日租金 System.out.println("\n【测试非法日租金设置】"); car1.setDailyRent(-100); // 应输出提示 System.out.println("当前日租金仍为:" + car1.getDailyRent() + " 元"); // 6. 输出总车辆数(静态成员) System.out.println("\n【系统总车辆数】:" + Car.getTotalCars() + " 辆"); System.out.println("\n=== 测试结束 ==="); } }