public class TrafficLamp2 {
public static void main(String[] args){
TrafficLamp lamp=TrafficLamp.RED;
System.out.println(lamp.nextTrafficLamp());
}
public enum TrafficLamp{
RED("GREEN"),GREEN("YELLOW"),YELLOW("RED");
private String traffic;
private TrafficLamp(String traffic){
this.traffic=traffic;
}
public TrafficLamp nextTrafficLamp(){
return TrafficLamp.valueOf(traffic);
}
}
}
|
|