ADD file via upload

main
pfvwqyiue 6 months ago
parent 3d2453fd7d
commit 74549f21da

@ -0,0 +1,119 @@
package com.automobile.parts;
/**
* -
*
*/
public class Transmission {
private String type;
private int gearCount;
private int currentGear;
private boolean automatic;
/**
* -
*/
public Transmission() {
this.type = "自动变速箱";
this.gearCount = 6;
this.currentGear = 0; // 空挡
this.automatic = true;
}
/**
*
* @param speed km/h
*/
public void shiftGears(int speed) {
int newGear;
if (speed == 0) {
newGear = 0; // 空挡
} else if (speed <= 20) {
newGear = 1;
} else if (speed <= 40) {
newGear = 2;
} else if (speed <= 60) {
newGear = 3;
} else if (speed <= 80) {
newGear = 4;
} else if (speed <= 120) {
newGear = 5;
} else {
newGear = 6;
}
if (newGear != currentGear) {
this.currentGear = newGear;
System.out.println("变速箱换挡到 " + getGearName(currentGear));
}
}
/**
*
* @param gear
* @return
*/
private String getGearName(int gear) {
switch (gear) {
case 0: return "空挡(N)";
case 1: return "1档";
case 2: return "2档";
case 3: return "3档";
case 4: return "4档";
case 5: return "5档";
case 6: return "6档";
default: return "未知档位";
}
}
/**
*
* @param gear
*/
public void manualShift(int gear) {
if (gear >= 0 && gear <= gearCount) {
this.currentGear = gear;
System.out.println("手动换挡到 " + getGearName(gear));
} else {
System.out.println("无效的档位选择");
}
}
/**
*
*/
public void reverse() {
this.currentGear = -1;
System.out.println("切换到倒挡(R)");
}
// Getter 和 Setter 方法
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 int getCurrentGear() {
return currentGear;
}
public boolean isAutomatic() {
return automatic;
}
public void setAutomatic(boolean automatic) {
this.automatic = automatic;
}
}
Loading…
Cancel
Save