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.

114 lines
2.7 KiB

package com.automobile.parts;
/**
* 座椅类 - 与汽车是组合关系
* 座椅是汽车的必要组成部分,不能独立于汽车存在
*/
public class Seat {
/**
* 座椅类型枚举
*/
public enum SeatType {
DRIVER, // 驾驶员座椅
PASSENGER, // 前排乘客座椅
REAR // 后排座椅
}
private SeatType type;
private String material;
private boolean heated;
private boolean ventilated;
private int position;
/**
* 构造方法 - 创建不同类型的座椅
* @param type 座椅类型
*/
public Seat(SeatType type) {
this.type = type;
this.material = "皮质座椅";
// 驾驶员座椅具有更多功能
if (type == SeatType.DRIVER) {
this.heated = true;
this.ventilated = true;
this.position = 5; // 默认位置
} else {
this.heated = type == SeatType.PASSENGER; // 前排乘客座椅有加热
this.ventilated = false;
this.position = 5; // 默认位置
}
}
/**
* 调整座椅位置
* @param newPosition 新位置
*/
public void adjustPosition(int newPosition) {
if (newPosition >= 1 && newPosition <= 10) {
this.position = newPosition;
System.out.println(type + " 座椅调整到位置 " + newPosition);
} else {
System.out.println("无效的座椅位置");
}
}
/**
* 开启加热功能
*/
public void turnOnHeating() {
if (heated) {
System.out.println(type + " 座椅加热已开启");
} else {
System.out.println(type + " 座椅不支持加热功能");
}
}
/**
* 开启通风功能
*/
public void turnOnVentilation() {
if (ventilated) {
System.out.println(type + " 座椅通风已开启");
} else {
System.out.println(type + " 座椅不支持通风功能");
}
}
// Getter 和 Setter 方法
public SeatType getType() {
return type;
}
public void setType(SeatType type) {
this.type = type;
}
public String getMaterial() {
return material;
}
public void setMaterial(String material) {
this.material = material;
}
public boolean isHeated() {
return heated;
}
public void setHeated(boolean heated) {
this.heated = heated;
}
public boolean isVentilated() {
return ventilated;
}
public void setVentilated(boolean ventilated) {
this.ventilated = ventilated;
}
public int getPosition() {
return position;
}
}