首页 > 代码库 > 黑马程序员——交通信号灯管理系统
黑马程序员——交通信号灯管理系统
题目:
模拟实现十字路口的交通灯管理系统逻辑,具体需求如下:
异步随机生成按照各个路线行驶的车辆。
例如:
由南向而来去往北向的车辆 右转车辆
由东向而来去往南向的车辆");
}
public Lamp blackOut(){
this.lighted = false;
if(opposite!=null){
Lamp.valueOf(opposite).blackOut();
}
Lamp nextLamp = null;
if(next!=null){
nextLamp = Lamp.valueOf(next);
System.out.println("绿灯从"+this.name()+"变为"+next);
nextLamp.light();
}
return nextLamp;
}
}
package com.itheima.interview;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
public class LampController {
private Lamp currentLamp;
LampController(){
this.currentLamp = Lamp.S2N;
currentLamp.light();
ScheduledExecutorService timer = Executors.newScheduledThreadPool(1);
timer.scheduleAtFixedRate(
new Runnable(){
public void run(){
currentLamp = currentLamp.blackOut();
}
},
10,
10,
TimeUnit.SECONDS);
}
}
package com.itheima.interview;
public class MainClass {
public static void main(String[] args) {
// TODO Auto-generated method stub
String[] directions = new String[]{
"S2N","S2W","E2W","E2S","N2S","N2E","W2E","W2N","S2E","E2N","N2W","W2S"
};
for(int i=0; i<directions.length;i++){
new Road(directions[i]);
}
new LampController();
}
}
详情请查看:http://edu.csdn.net/heima
黑马程序员——交通信号灯管理系统
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。