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.

66 lines
1.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.car.model;
/**
* 变速箱类 - 汽车的传动组件
* 与Car类是组合关系与Engine和Wheel有交互关系
*/
public class Transmission {
private String type; // 变速箱类型 (自动/手动)
private int gearCount; // 档位数量
private boolean hasSportMode; // 是否有运动模式
/**
* 构造方法
* @param type 变速箱类型
* @param gearCount 档位数量
* @param hasSportMode 是否有运动模式
*/
public Transmission(String type, int gearCount, boolean hasSportMode) {
this.type = type;
this.gearCount = gearCount;
this.hasSportMode = hasSportMode;
}
/**
* 换挡方法
* @param gear 目标档位
* @return 是否换挡成功
*/
public boolean shiftGear(int gear) {
if (gear >= 1 && gear <= gearCount) {
System.out.println("Shifting to gear: " + gear);
return true;
}
return false;
}
// getter and setter methods
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public int getGearCount() {
return gearCount;
}
public void setGearCount(int gearCount) {
this.gearCount = gearCount;
}
public boolean hasSportMode() {
return hasSportMode;
}
public void setSportMode(boolean hasSportMode) {
this.hasSportMode = hasSportMode;
}
@Override
public String toString() {
return "Transmission [type=" + type + ", gearCount=" + gearCount + ", hasSportMode=" + hasSportMode + "]";
}
}