このメソッドを作成するのに問題があります。正しくやっていると思っていましたが、明らかにそうではありません。changeLight() メソッドに取り組んでいますが、if ステートメントに赤線が引かれています。なぜかわからない。メソッドは currentState を調べて変更する必要があります。currentState が State.GO の場合は State.WARN に変更し、currentState が State.Warn の場合は State.STOP に変更し、現在の状態が State の場合は State.STOP に変更する必要があります。 STOP すると、State.GO に変わります。これは単純な信号プログラムです。
ここで少し助けが必要です。感謝します。
これが私のコードです。
package trafficlight;
import java.awt.Color;
public class TrafficLight {
private int goDuration;
private int stopDuration;
private int warnDuration;
public enum State {STOP, GO, WARN};
public Color GO_COLOR = Color.green;
public Color STOP_COLOR = Color.red;
public Color OFF_COLOR = Color.darkGray;
public Color WARNING_COLOR = Color.yellow;
private State currentState;
public static void main(String[] args) {
}
public TrafficLight(int goDuration, int stopDuration, int warnDuration) {
this.goDuration = goDuration = 2;
this.stopDuration = stopDuration = 2;
this.warnDuration = warnDuration = 1;
this.currentState = currentState = State.GO;
}
public static void changeLight() {
if (currentState = State.GO) {
currentState = State.WARN;
}
}
public int getGoDuration() {
return goDuration;
}
public void setGoDuration(int goDuration) {
this.goDuration = goDuration;
}
public int getStopDuration() {
return stopDuration;
}
public void setStopDuration(int stopDuration) {
this.stopDuration = stopDuration;
}
public int getWarnDuration() {
return warnDuration;
}
public void setWarnDuration(int warnDuration) {
this.warnDuration = warnDuration;
}
public State getCurrentState() {
return currentState;
}
public void setCurrentState(State currentState) {
this.currentState = currentState;
}
}