|
|
|
|
@ -0,0 +1,140 @@
|
|
|
|
|
package com.car.service;
|
|
|
|
|
|
|
|
|
|
import com.car.model.*;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 汽车维修系统类 - 展示组合关系中部件的更换和维修
|
|
|
|
|
*/
|
|
|
|
|
public class CarRepairSystem {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 维修汽车
|
|
|
|
|
* @param car 需要维修的汽车
|
|
|
|
|
*/
|
|
|
|
|
public void repairCar(Car car) {
|
|
|
|
|
System.out.println("Starting repair for " + car.getBrand() + " " + car.getModel() + "...");
|
|
|
|
|
|
|
|
|
|
// 运行诊断
|
|
|
|
|
boolean diagnosticsResult = car.runDiagnostics();
|
|
|
|
|
|
|
|
|
|
if (!diagnosticsResult) {
|
|
|
|
|
System.out.println("Repairing detected issues...");
|
|
|
|
|
// 这里可以添加具体的维修逻辑
|
|
|
|
|
fixCommonIssues(car);
|
|
|
|
|
System.out.println("Basic repairs completed. Running final diagnostics...");
|
|
|
|
|
car.runDiagnostics();
|
|
|
|
|
} else {
|
|
|
|
|
System.out.println("No issues detected. Car is in good condition.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
System.out.println("Repair service completed.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 更换汽车部件
|
|
|
|
|
* @param car 汽车对象
|
|
|
|
|
* @param partType 部件类型
|
|
|
|
|
* @param partIndex 部件索引(多部件时使用)
|
|
|
|
|
*/
|
|
|
|
|
public void replacePart(Car car, String partType, int partIndex) {
|
|
|
|
|
switch (partType.toLowerCase()) {
|
|
|
|
|
case "steeringwheel":
|
|
|
|
|
car.replaceSteeringWheel(new SteeringWheel("Premium Leather", "370mm", true));
|
|
|
|
|
System.out.println("Replaced steering wheel with premium leather version.");
|
|
|
|
|
break;
|
|
|
|
|
case "seat":
|
|
|
|
|
if (car.replaceSeat(partIndex, new Seat(
|
|
|
|
|
partIndex == 0 ? "Driver" : "Passenger",
|
|
|
|
|
"Memory Foam Leather",
|
|
|
|
|
true,
|
|
|
|
|
true))) {
|
|
|
|
|
System.out.println("Seat replaced successfully.");
|
|
|
|
|
} else {
|
|
|
|
|
System.out.println("Invalid seat position.");
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case "wheel":
|
|
|
|
|
if (car.replaceWheel(partIndex, new Wheel("19 inch", "All-season Performance", 32))) {
|
|
|
|
|
System.out.println("Wheel replaced successfully.");
|
|
|
|
|
} else {
|
|
|
|
|
System.out.println("Invalid wheel position.");
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case "engine":
|
|
|
|
|
car.setEngine(new Engine("V8", 450, 5.0, 8));
|
|
|
|
|
System.out.println("Engine replaced with V8 performance engine.");
|
|
|
|
|
break;
|
|
|
|
|
case "transmission":
|
|
|
|
|
car.setTransmission(new Transmission("Dual Clutch", 8, true));
|
|
|
|
|
System.out.println("Transmission replaced with dual-clutch system.");
|
|
|
|
|
break;
|
|
|
|
|
case "ecu":
|
|
|
|
|
ElectronicSystem es = car.getElectronicSystem();
|
|
|
|
|
if (es.replaceECU(partIndex, new ElectronicControlUnit(
|
|
|
|
|
"Upgraded ECU",
|
|
|
|
|
"Enhanced performance control"))) {
|
|
|
|
|
System.out.println("ECU replaced successfully.");
|
|
|
|
|
} else {
|
|
|
|
|
System.out.println("Invalid ECU index.");
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
System.out.println("Unknown part type: " + partType);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 检查和维修引擎活塞
|
|
|
|
|
* @param car 汽车对象
|
|
|
|
|
* @param pistonIndex 活塞索引
|
|
|
|
|
*/
|
|
|
|
|
public void repairEnginePiston(Car car, int pistonIndex) {
|
|
|
|
|
Engine engine = car.getEngine();
|
|
|
|
|
if (engine.replacePiston(pistonIndex, new Piston(86, 89, "High-strength Aluminum", 11))) {
|
|
|
|
|
System.out.println("Engine piston " + pistonIndex + " replaced with high-performance version.");
|
|
|
|
|
} else {
|
|
|
|
|
System.out.println("Invalid piston index.");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 修复常见问题
|
|
|
|
|
* @param car 汽车对象
|
|
|
|
|
*/
|
|
|
|
|
private void fixCommonIssues(Car car) {
|
|
|
|
|
// 修复轮胎气压
|
|
|
|
|
for (int i = 0; i < car.getWheels().size(); i++) {
|
|
|
|
|
Wheel wheel = car.getWheels().get(i);
|
|
|
|
|
wheel.setPressure(32); // 设置标准气压
|
|
|
|
|
System.out.println("Adjusted wheel " + i + " pressure to standard level.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 重置电子系统
|
|
|
|
|
ElectronicSystem es = car.getElectronicSystem();
|
|
|
|
|
for (ElectronicControlUnit ecu : es.getEcuList()) {
|
|
|
|
|
if (!ecu.isOperational()) {
|
|
|
|
|
ecu.reset();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 执行定期保养
|
|
|
|
|
* @param car 汽车对象
|
|
|
|
|
*/
|
|
|
|
|
public void performMaintenance(Car car) {
|
|
|
|
|
System.out.println("Performing scheduled maintenance for " + car.getBrand() + " " + car.getModel());
|
|
|
|
|
|
|
|
|
|
// 检查并调整所有系统
|
|
|
|
|
System.out.println("- Checking engine oil level");
|
|
|
|
|
System.out.println("- Checking coolant level");
|
|
|
|
|
System.out.println("- Checking brake fluid");
|
|
|
|
|
System.out.println("- Inspecting tires");
|
|
|
|
|
System.out.println("- Lubricating moving parts");
|
|
|
|
|
|
|
|
|
|
// 运行完整诊断
|
|
|
|
|
car.runDiagnostics();
|
|
|
|
|
|
|
|
|
|
System.out.println("Maintenance completed successfully.");
|
|
|
|
|
}
|
|
|
|
|
}
|