ADD file via upload

main
pc9pizjb6 4 months ago
parent dd1d934b41
commit 89f246b5de

@ -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.");
}
}
Loading…
Cancel
Save