public class Testcar { public static void main(String[] args) { // 1. 创建3个Car对象(使用不同构造方法) Car car1 = new Car("京A12345", "丰田", "凯美瑞", 280.0); Car car2 = new Car("沪B67890", "本田", "雅阁"); // 默认日租金300 Car car3 = new Car("粤C24680", "大众", "帕萨特", 320.0); // 2. 输出所有车辆信息 System.out.println("===== 初始车辆信息 ====="); car1.displayInfo(); car2.displayInfo(); car3.displayInfo(); // 3. 测试租车/还车业务 System.out.println("===== 测试租车/还车 ====="); car1.rentCar(); // 正常租车 car1.rentCar(); // 重复租车(提示错误) car1.returnCar(); // 正常还车 car1.returnCar(); // 重复还车(提示错误) // 4. 计算租金(5天) System.out.println("===== 计算租金 ====="); double rent = car1.calculateRent(5); System.out.printf("京A12345 租用5天,总租金:%.2f元%n%n", rent); // 5. 测试非法日租金修改 System.out.println("===== 测试非法租金修改 ====="); car1.setDailyRent(-100); // 输入非法值,提示错误 System.out.println("修改后日租金:" + car1.getDailyRent() + "元/天(保持原值)%n"); // 6. 输出总车辆数(静态成员) System.out.println("===== 车辆总数 ====="); System.out.println("当前系统共有车辆:" + Car.getTotalCars() + "辆"); } }