本帖最后由 NNERO 于 2014-4-21 16:02 编辑
- public enum Lamp {
- S2N("N2S","S2W",false),S2W("N2E","E2W",false),E2W("W2E","E2S",false),E2S("W2N","S2N",false),
- N2S(null,null,false),N2E(null,null,false),W2E(null,null,false),W2N(null,null,false),
- S2E(null,null,true),E2N(null,null,true),N2W(null,null,true),W2S(null,null,true);
-
- private boolean lighted;
- private String opposite;
- private String next;
-
- private Lamp(String oppsite,String next,boolean lighted){//构造方法为何必须私有,我创建公有就报错了。。
- this.opposite=oppsite;
- this.next=next;
- this.lighted=lighted;
- }
-
- public boolean isLighted(){
- return lighted;
- }
-
- public void light(){
- this.lighted=true;
- if(opposite!=null){
- Lamp.valueOf(opposite).light();
- }
- System.out.println(name()+"...."+"Green"+"有6个方向车正在行驶");
- }
-
- public Lamp black(){
- this.lighted=false;
- if(opposite!=null){
- Lamp.valueOf(opposite).black();
- }
- Lamp lampNext = null;//这里是为何,看视频没看懂,为何要拿出来
- if(next!=null){
- lampNext =Lamp.valueOf(next);
- System.out.println("Green"+name()+"------->"+next);
- lampNext.light();
- }
- return lampNext;
- }
- }
复制代码 注释里的2个问题,求高手解答!!!!
|