From 239593bb85fab04ceab7edc234dd0cb62c152bbe Mon Sep 17 00:00:00 2001 From: Wangyanshu <2680603193@qq.com> Date: Thu, 2 Apr 2026 00:55:02 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20'TestCar'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TestCar | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 TestCar diff --git a/TestCar b/TestCar new file mode 100644 index 0000000..7837355 --- /dev/null +++ b/TestCar @@ -0,0 +1,51 @@ +package com.rental; + +public class TestCar { + public static void main(String[] args) { + System.out.println("===== 车辆管理系统测试 =====\n"); + + Car car1 = new Car("京A12345", "大众", "朗逸", 200.0); + Car car2 = new Car("沪B67890", "丰田", "凯美瑞", 350.0); + Car car3 = new Car("粤C24680", "本田", "雅阁"); + + System.out.println("=== 创建的车辆信息 ==="); + car1.displayInfo(); + car2.displayInfo(); + car3.displayInfo(); + + System.out.println("\n=== 测试租车功能 ==="); + System.out.println("对车辆1进行租车操作:"); + car1.rentCar(); + System.out.println("再次尝试租车:"); + car1.rentCar(); + + System.out.println("\n=== 测试还车功能 ==="); + System.out.println("对车辆1进行还车操作:"); + car1.returnCar(); + System.out.println("再次尝试还车:"); + car1.returnCar(); + + System.out.println("\n=== 测试租金计算 ==="); + System.out.println("车辆2租用5天的费用:" + car2.calculateRent(5) + " 元"); + System.out.println("车辆3租用3天的费用:" + car3.calculateRent(3) + " 元"); + + System.out.println("\n=== 测试setter数据校验 ==="); + System.out.println("尝试将车辆1的日租金设置为-100:"); + car1.setDailyRent(-100); + System.out.println("车辆1当前日租金:" + car1.getDailyRent()); + System.out.println("将车辆1的日租金设置为250:"); + car1.setDailyRent(250); + System.out.println("车辆1当前日租金:" + car1.getDailyRent()); + + System.out.println("\n=== 测试品牌和型号修改 ==="); + car1.setBrand("奥迪"); + car1.setModel("A4"); + System.out.println("修改后的车辆1信息:"); + car1.displayInfo(); + + System.out.println("\n=== 车辆总数统计 ==="); + System.out.println("总车辆数:" + Car.getTotalCars() + " 辆"); + + System.out.println("\n=== 测试完成 ==="); + } +} \ No newline at end of file