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.
Car/ElectronicControlUnit.java

109 lines
2.6 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package com.automobile.system;
/**
* 电子控制单元类 - 与电子系统是组合关系
* ECU是电子系统的必要组成部分不能独立于电子系统存在
*/
public class ElectronicControlUnit {
private String type;
private String abbreviation;
private String version;
private boolean running;
private int faultCode;
/**
* 构造方法 - 创建电子控制单元时设置基本属性
* @param type 控制单元类型
* @param abbreviation 缩写
*/
public ElectronicControlUnit(String type, String abbreviation) {
this.type = type;
this.abbreviation = abbreviation;
this.version = "1.0.0";
this.running = false;
this.faultCode = 0; // 0表示无故障
}
/**
* 初始化ECU
*/
public void initialize() {
this.running = true;
System.out.println(abbreviation + " (" + type + ") 初始化完成");
}
/**
* 关闭ECU
*/
public void shutdown() {
this.running = false;
System.out.println(abbreviation + " (" + type + ") 已关闭");
}
/**
* 执行自检
*/
public void runSelfTest() {
if (running) {
System.out.println(abbreviation + " 自检: " +
(faultCode == 0 ? "正常" : "故障代码: " + faultCode));
} else {
System.out.println(abbreviation + " 未运行");
}
}
/**
* 更新软件版本
* @param newVersion 新版本号
*/
public void updateSoftware(String newVersion) {
this.version = newVersion;
System.out.println(abbreviation + " 软件更新到版本 " + newVersion);
}
/**
* 设置故障代码
* @param code 故障代码
*/
public void setFault(int code) {
this.faultCode = code;
System.out.println(abbreviation + " 记录故障代码: " + code);
}
/**
* 清除故障
*/
public void clearFault() {
this.faultCode = 0;
System.out.println(abbreviation + " 故障已清除");
}
// Getter 和 Setter 方法
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getAbbreviation() {
return abbreviation;
}
public void setAbbreviation(String abbreviation) {
this.abbreviation = abbreviation;
}
public String getVersion() {
return version;
}
public boolean isRunning() {
return running;
}
public int getFaultCode() {
return faultCode;
}
}