下载此文档

java 交通灯管理系统源代码.doc


文档分类:IT计算机 | 页数:约9页 举报非法文档有奖
1/9
下载提示
  • 1.该资料是网友上传的,本站提供全文预览,预览什么样,下载就什么样。
  • 2.下载该文档所得收入归上传者、原创者。
  • 3.下载的文档,不会出现我们的网址水印。
1/9 下载此文档
文档列表 文档介绍
package;import;import;import;import;import;import;import;/***每个Road对象代表一条路线,总共有12条路线,即系统中总共要产生12个Road实例对象。*每条路线上随机增加新的车辆,增加到一个集合中保存。*每条路线每隔一秒都会检查控制本路线的灯是否为绿,是则将本路线保存车的集合中的第一辆车移除,即表示车穿过了路口。****@author张孝祥**/lassRoad{ privateList<String>vechicles=newArrayList<String>(); privateStringname=null; publicRoad(Stringname){ =name; //模拟车辆不断随机上路的过程 ExecutorServicepool=(); (newRunnable(){ publicvoidrun(){ for(inti=1;i<1000;i++){ try{ ((newRandom().nextInt(10)+1)*1000); }catch(InterruptedExceptione){ (); } (+"_"+i); } } }); //每隔一秒检查对应的灯是否为绿,是则放行一辆车 ScheduledExecutorServicetimer=(1); ( newRunnable(){ publicvoidrun(){ if(()>0){ booleanlighted=(; if(lighted){ +"istraversing!"); } } } }, 1, 1, ); }}package;lassMainClass{ /** ****@paramargs */ publicstaticvoidmain(String[]args){ /*产生12个方向的路线*/ String[]directions=newString[]{ "S2N","S2W","E2W","E2S","N2S","N2E","W2E","W2N","S2E","E2N","N2W","W2S" }; for(inti=0;i<;i++){ newRoad(directions[i]); } /*产生整个交通灯系统*/ newLampController(); }}package;import;import;import;lassLampController{ privateLampcurrentLamp; publicLampController(){ //刚开始让由南向北的灯变绿; currentLamp=; (); /*每隔10秒将当前绿灯变为红灯,并让下一个方向的灯变绿*/ ScheduledExecutorServicetimer=E

java 交通灯管理系统源代码 来自淘豆网m.daumloan.com转载请标明出处.

相关文档 更多>>
非法内容举报中心
文档信息
  • 页数9
  • 收藏数0 收藏
  • 顶次数0
  • 上传人坐水行舟
  • 文件大小29 KB
  • 时间2019-06-16
最近更新