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 + "]"; } }