|
|
package com.automobile.configuration;
|
|
|
|
|
|
import com.automobile.model.Car;
|
|
|
import com.automobile.parts.Engine;
|
|
|
import com.automobile.parts.SteeringWheel;
|
|
|
import com.automobile.parts.Seat;
|
|
|
import com.automobile.parts.Transmission;
|
|
|
import com.automobile.parts.Wheel;
|
|
|
import com.automobile.system.ElectronicSystem;
|
|
|
|
|
|
/**
|
|
|
* 汽车配置系统类
|
|
|
* 允许用户自定义汽车的各种组合部件
|
|
|
*/
|
|
|
public class ConfigurationSystem {
|
|
|
private String customerName;
|
|
|
private CarConfig currentConfig;
|
|
|
|
|
|
/**
|
|
|
* 构造方法
|
|
|
* @param customerName 客户名称
|
|
|
*/
|
|
|
public ConfigurationSystem(String customerName) {
|
|
|
this.customerName = customerName;
|
|
|
this.currentConfig = new CarConfig();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 开始新的配置
|
|
|
*/
|
|
|
public void startNewConfiguration() {
|
|
|
this.currentConfig = new CarConfig();
|
|
|
System.out.println("开始新的汽车配置");
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 设置汽车品牌和型号
|
|
|
* @param brand 品牌
|
|
|
* @param model 型号
|
|
|
*/
|
|
|
public void setCarDetails(String brand, String model) {
|
|
|
currentConfig.setBrand(brand);
|
|
|
currentConfig.setModel(model);
|
|
|
System.out.println("设置汽车: " + brand + " " + model);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 配置方向盘
|
|
|
* @param type 方向盘类型
|
|
|
* @param powerAssisted 是否助力
|
|
|
*/
|
|
|
public void configureSteeringWheel(String type, boolean powerAssisted) {
|
|
|
currentConfig.setSteeringWheelType(type);
|
|
|
currentConfig.setPowerAssisted(powerAssisted);
|
|
|
System.out.println("配置方向盘: " + type + (powerAssisted ? " (助力)" : " (非助力)"));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 配置座椅
|
|
|
* @param seatCount 座椅数量
|
|
|
* @param heated 是否加热
|
|
|
* @param ventilated 是否通风
|
|
|
*/
|
|
|
public void configureSeats(int seatCount, boolean heated, boolean ventilated) {
|
|
|
currentConfig.setSeatCount(seatCount);
|
|
|
currentConfig.setHeatedSeats(heated);
|
|
|
currentConfig.setVentilatedSeats(ventilated);
|
|
|
System.out.println("配置座椅: " + seatCount + "个座位, " +
|
|
|
(heated ? "加热 " : "") + (ventilated ? "通风" : ""));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 配置引擎
|
|
|
* @param cylinders 气缸数
|
|
|
* @param horsepower 马力
|
|
|
*/
|
|
|
public void configureEngine(int cylinders, int horsepower) {
|
|
|
currentConfig.setCylinderCount(cylinders);
|
|
|
currentConfig.setHorsepower(horsepower);
|
|
|
System.out.println("配置引擎: " + cylinders + "缸, " + horsepower + "马力");
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 配置变速箱
|
|
|
* @param automatic 是否自动
|
|
|
* @param gearCount 档位数量
|
|
|
*/
|
|
|
public void configureTransmission(boolean automatic, int gearCount) {
|
|
|
currentConfig.setAutomaticTransmission(automatic);
|
|
|
currentConfig.setGearCount(gearCount);
|
|
|
System.out.println("配置变速箱: " + (automatic ? "自动" : "手动") + ", " + gearCount + "档");
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 配置车轮
|
|
|
* @param diameter 直径
|
|
|
* @param brand 品牌
|
|
|
*/
|
|
|
public void configureWheels(double diameter, String brand) {
|
|
|
currentConfig.setWheelDiameter(diameter);
|
|
|
currentConfig.setWheelBrand(brand);
|
|
|
System.out.println("配置车轮: " + diameter + "英寸, " + brand);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 确认配置并生成汽车
|
|
|
* @return 按照配置生成的汽车实例
|
|
|
*/
|
|
|
public Car confirmConfiguration() {
|
|
|
System.out.println("\n===== 配置确认 =====");
|
|
|
System.out.println("客户: " + customerName);
|
|
|
System.out.println("汽车: " + currentConfig.getBrand() + " " + currentConfig.getModel());
|
|
|
System.out.println("方向盘: " + currentConfig.getSteeringWheelType());
|
|
|
System.out.println("座椅: " + currentConfig.getSeatCount() + "个");
|
|
|
System.out.println("引擎: " + currentConfig.getCylinderCount() + "缸, " + currentConfig.getHorsepower() + "马力");
|
|
|
System.out.println("变速箱: " + (currentConfig.isAutomaticTransmission() ? "自动" : "手动"));
|
|
|
System.out.println("车轮: " + currentConfig.getWheelDiameter() + "英寸");
|
|
|
System.out.println("==================\n");
|
|
|
|
|
|
// 这里简化处理,实际应该根据配置创建定制化的汽车
|
|
|
return new Car(currentConfig.getBrand(), currentConfig.getModel(), generateVIN());
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 生成VIN码(简化版)
|
|
|
* @return VIN码
|
|
|
*/
|
|
|
private String generateVIN() {
|
|
|
return "VIN" + System.currentTimeMillis();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 内部类:汽车配置
|
|
|
*/
|
|
|
private static class CarConfig {
|
|
|
private String brand = "未知";
|
|
|
private String model = "未知";
|
|
|
private String steeringWheelType = "皮质方向盘";
|
|
|
private boolean powerAssisted = true;
|
|
|
private int seatCount = 5;
|
|
|
private boolean heatedSeats = false;
|
|
|
private boolean ventilatedSeats = false;
|
|
|
private int cylinderCount = 4;
|
|
|
private int horsepower = 150;
|
|
|
private boolean automaticTransmission = true;
|
|
|
private int gearCount = 6;
|
|
|
private double wheelDiameter = 17.0;
|
|
|
private String wheelBrand = "标准";
|
|
|
|
|
|
// Getter 和 Setter 方法
|
|
|
public String getBrand() { return brand; }
|
|
|
public void setBrand(String brand) { this.brand = brand; }
|
|
|
|
|
|
public String getModel() { return model; }
|
|
|
public void setModel(String model) { this.model = model; }
|
|
|
|
|
|
public String getSteeringWheelType() { return steeringWheelType; }
|
|
|
public void setSteeringWheelType(String steeringWheelType) { this.steeringWheelType = steeringWheelType; }
|
|
|
|
|
|
public boolean isPowerAssisted() { return powerAssisted; }
|
|
|
public void setPowerAssisted(boolean powerAssisted) { this.powerAssisted = powerAssisted; }
|
|
|
|
|
|
public int getSeatCount() { return seatCount; }
|
|
|
public void setSeatCount(int seatCount) { this.seatCount = seatCount; }
|
|
|
|
|
|
public boolean isHeatedSeats() { return heatedSeats; }
|
|
|
public void setHeatedSeats(boolean heatedSeats) { this.heatedSeats = heatedSeats; }
|
|
|
|
|
|
public boolean isVentilatedSeats() { return ventilatedSeats; }
|
|
|
public void setVentilatedSeats(boolean ventilatedSeats) { this.ventilatedSeats = ventilatedSeats; }
|
|
|
|
|
|
public int getCylinderCount() { return cylinderCount; }
|
|
|
public void setCylinderCount(int cylinderCount) { this.cylinderCount = cylinderCount; }
|
|
|
|
|
|
public int getHorsepower() { return horsepower; }
|
|
|
public void setHorsepower(int horsepower) { this.horsepower = horsepower; }
|
|
|
|
|
|
public boolean isAutomaticTransmission() { return automaticTransmission; }
|
|
|
public void setAutomaticTransmission(boolean automaticTransmission) { this.automaticTransmission = automaticTransmission; }
|
|
|
|
|
|
public int getGearCount() { return gearCount; }
|
|
|
public void setGearCount(int gearCount) { this.gearCount = gearCount; }
|
|
|
|
|
|
public double getWheelDiameter() { return wheelDiameter; }
|
|
|
public void setWheelDiameter(double wheelDiameter) { this.wheelDiameter = wheelDiameter; }
|
|
|
|
|
|
public String getWheelBrand() { return wheelBrand; }
|
|
|
public void setWheelBrand(String wheelBrand) { this.wheelBrand = wheelBrand; }
|
|
|
}
|
|
|
} |