package com.car; import com.car.config.CarConfig; import com.car.config.CarConfigurationSystem; import com.car.manufacture.CarManufacturingSystem; import com.car.model.*; import com.car.service.CarRepairSystem; /** * 主测试类 - 测试所有实现的功能 */ public class MainTest { public static void main(String[] args) { System.out.println("===== Car System Implementation Test ====="); // 测试基础功能 testBasicCarFunctionality(); System.out.println("\n===== Car Configuration System Test ====="); // 测试汽车配置系统 testCarConfigurationSystem(); System.out.println("\n===== Car Manufacturing System Test ====="); // 测试汽车制造系统 testCarManufacturingSystem(); System.out.println("\n===== Car Repair System Test ====="); // 测试汽车维修系统 testCarRepairSystem(); System.out.println("\n===== All Tests Completed Successfully ====="); } /** * 测试基础汽车功能 */ private static void testBasicCarFunctionality() { System.out.println("Creating a basic car..."); Car car = new Car("Toyota", "Camry", "2024"); System.out.println("Car details: " + car); // 测试启动和停止 car.start(); car.stop(); // 测试组件信息 System.out.println("Steering wheel: " + car.getSteeringWheel()); System.out.println("Driver seat: " + car.getSeats().get(0)); System.out.println("Engine: " + car.getEngine()); System.out.println("Transmission: " + car.getTransmission()); System.out.println("Electronic system: " + car.getElectronicSystem()); System.out.println("Wheel 0: " + car.getWheels().get(0)); // 测试诊断功能 car.runDiagnostics(); } /** * 测试汽车配置系统 */ private static void testCarConfigurationSystem() { CarConfigurationSystem configSystem = new CarConfigurationSystem(); // 创建自定义配置 CarConfig customConfig = new CarConfig(); customConfig.setSteeringWheelMaterial("Carbon Fiber"); customConfig.setSteeringWheelDiameter("360mm"); customConfig.setDriverSeatMaterial("Premium Leather"); customConfig.setEngineType("V8"); customConfig.setEngineHorsepower(450); customConfig.setWheelSize("20 inch"); // 配置自定义汽车 Car customCar = configSystem.configureCar("BMW", "M5", "2024", customConfig); // 验证配置是否生效 System.out.println("Custom car created: " + customCar); System.out.println("Custom steering wheel: " + customCar.getSteeringWheel()); System.out.println("Custom engine: " + customCar.getEngine()); System.out.println("Custom wheel: " + customCar.getWheels().get(0)); } /** * 测试汽车制造系统 */ private static void testCarManufacturingSystem() { CarManufacturingSystem manufacturingSystem = new CarManufacturingSystem(); // 制造标准汽车 Car standardCar = manufacturingSystem.manufactureStandardCar("Honda", "Accord", "2024"); // 创建并制造自定义汽车 CarConfig sportConfig = new CarConfig(); sportConfig.setEngineType("V6 Twin-Turbo"); sportConfig.setEngineHorsepower(400); sportConfig.setTransmissionType("Dual Clutch"); sportConfig.setWheelSize("21 inch"); sportConfig.setWheelType("Performance"); Car sportsCar = manufacturingSystem.manufactureCustomCar("Audi", "RS7", "2024", sportConfig); // 显示制造统计 System.out.println(manufacturingSystem.getManufacturingStats()); } /** * 测试汽车维修系统 */ private static void testCarRepairSystem() { CarRepairSystem repairSystem = new CarRepairSystem(); // 创建一辆测试汽车 Car carForRepair = new Car("Ford", "Mustang", "2022"); // 修改一些部件使其需要维修(模拟故障) // 将一个ECU设置为非运行状态 carForRepair.getElectronicSystem().getEcuList().get(0).setOperational(false); // 修改轮胎气压 carForRepair.getWheels().get(0).setPressure(25); // 低于标准 // 执行维修 repairSystem.repairCar(carForRepair); // 测试部件更换 System.out.println("\nTesting component replacement:"); repairSystem.replacePart(carForRepair, "steeringwheel", 0); repairSystem.replacePart(carForRepair, "seat", 0); repairSystem.replacePart(carForRepair, "wheel", 0); // 测试活塞维修 repairSystem.repairEnginePiston(carForRepair, 0); // 执行定期保养 System.out.println("\nPerforming scheduled maintenance:"); repairSystem.performMaintenance(carForRepair); } }