码迷,mamicode.com
首页 > 其他好文 > 详细

黑马程序员——交通信号灯管理系统

时间:2014-09-07 00:59:54      阅读:278      评论:0      收藏:0      [点我收藏+]

标签:http   os   io   java   ar   for   div   cti   sp   

 
题目:
 
模拟实现十字路口的交通灯管理系统逻辑,具体需求如下:
 
异步随机生成按照各个路线行驶的车辆。
 
例如:
 
由南向而来去往北向的车辆 右转车辆
 
由东向而来去往南向的车辆");
 }
 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

黑马程序员——交通信号灯管理系统

标签:http   os   io   java   ar   for   div   cti   sp   

原文地址:http://www.cnblogs.com/yzcorange/p/3960015.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!