You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
sdf/CarConfigurationSystem.java

101 lines
3.2 KiB

package com.car.config;
import com.car.model.*;
/**
* 汽车配置系统类 - 允许用户自定义汽车的各种组合部件
*/
public class CarConfigurationSystem {
/**
* 创建自定义配置的汽车
* @param brand 品牌
* @param model 型号
* @param year 年份
* @param config 配置选项
* @return 配置好的汽车
*/
public Car configureCar(String brand, String model, String year, CarConfig config) {
Car car = new Car(brand, model, year);
// 根据配置自定义汽车组件
if (config != null) {
// 配置方向盘
if (config.getSteeringWheelMaterial() != null) {
SteeringWheel customWheel = new SteeringWheel(
config.getSteeringWheelMaterial(),
config.getSteeringWheelDiameter(),
config.isSteeringWheelAirbag()
);
car.replaceSteeringWheel(customWheel);
}
// 配置座椅
if (config.getDriverSeatMaterial() != null) {
Seat customDriverSeat = new Seat(
"Driver",
config.getDriverSeatMaterial(),
true,
config.isDriverSeatHeated()
);
car.replaceSeat(0, customDriverSeat);
}
// 配置引擎
if (config.getEngineType() != null) {
Engine customEngine = new Engine(
config.getEngineType(),
config.getEngineHorsepower(),
config.getEngineDisplacement(),
config.getEnginePistonCount()
);
car.setEngine(customEngine);
}
// 配置变速箱
if (config.getTransmissionType() != null) {
Transmission customTrans = new Transmission(
config.getTransmissionType(),
config.getTransmissionGears(),
config.isTransmissionSportMode()
);
car.setTransmission(customTrans);
}
// 配置车轮
if (config.getWheelSize() != null) {
Wheel customWheel = new Wheel(
config.getWheelSize(),
config.getWheelType(),
32 // 默认气压
);
// 更换所有四个车轮
for (int i = 0; i < 4; i++) {
car.replaceWheel(i, customWheel);
}
}
}
System.out.println("Custom car configured successfully!");
return car;
}
/**
* 创建标准配置的汽车
* @param brand 品牌
* @param model 型号
* @param year 年份
* @return 标准配置的汽车
*/
public Car createStandardCar(String brand, String model, String year) {
return new Car(brand, model, year);
}
/**
* 获取默认配置
* @return 默认配置对象
*/
public CarConfig getDefaultConfig() {
return new CarConfig();
}
}