java 肯定可以,首先要解決虛擬機(jī),就是電梯程序當(dāng)中要有虛擬機(jī)運(yùn)行,然后在虛擬機(jī)的基礎(chǔ)上編寫(xiě)java程序去執(zhí)行。

成都創(chuàng)新互聯(lián)主營(yíng)茫崖網(wǎng)站建設(shè)的網(wǎng)絡(luò)公司,主營(yíng)網(wǎng)站建設(shè)方案,成都APP應(yīng)用開(kāi)發(fā),茫崖h5微信小程序定制開(kāi)發(fā)搭建,茫崖網(wǎng)站營(yíng)銷推廣歡迎茫崖等地區(qū)企業(yè)咨詢
但是一般直接和硬件交互 一般用PLC
public static void main(String[] args) {
/*Lianxi1 lx = new Lianxi1();
lx.method();*/
boolean flag = new Lianxi1().byLift();
if(flag == true){
System.out.println("沒(méi)有地下室 開(kāi)門(mén)");
}else
System.out.println("關(guān)門(mén)");
}
public boolean byLift(){
Random ran = new Random();
int num = Math.abs(ran.nextInt(1000));//總承受的重量
Random ran1 = new Random();
int floor = Math.abs(ran1.nextInt(5));//樓層數(shù) 1-5隨機(jī)
switch (num){
case 1000:
System.out.println("超重,發(fā)出警報(bào) 無(wú)法關(guān)門(mén)");
break;
default:
System.out.println("電梯關(guān)門(mén)");
break;
}
//選擇樓層 1-5返回true 關(guān)門(mén)
switch (floor) {
case 1:
return true;
case 2:
return true;
case 3:
return true;
case 4:
return true;
case 5:
return true;
default:
return false;
}
}
這是我回答前幾天和你一樣想要的電梯程序 是單箱的 希望能幫助你 package bean; public class dianti { int on=1;//定義一個(gè)初始化樓層 初始化是在1層 //先從簡(jiǎn)單的開(kāi)始 我們先寫(xiě)兩個(gè)方法 一個(gè)是在電梯外面方法 一個(gè)是在電梯內(nèi)部的方法 public void wai(int num)//外部方法 { if(num==this.on) { System.out.println("停留在本層 直接開(kāi)門(mén)"); } else if(numthis.on) { Thread th = new Thread(); for(int i=this.on;i=num;i++) { if(i==num) { System.out.println("電梯到達(dá)~開(kāi)門(mén)請(qǐng)進(jìn)···"); this.on=num; } else { System.out.println("電梯在"+i+"層 馬上就到,請(qǐng)等待····"); try { th.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } } } } else if(num0numthis.on) { System.out.println("進(jìn)來(lái)了" +num+" "+this.on); Thread th1 = new Thread(); for(int u=this.on;u=num;u--) { if(u==num) { System.out.println("電梯到達(dá)~開(kāi)門(mén)請(qǐng)進(jìn)···"); this.on=num; } else { System.out.println("電梯在"+u+"層 馬上就到,請(qǐng)等待····"); try { th1.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } } } } else { System.out.println("1111111111111"); } } //內(nèi)部方法 public void nei(int num) { System.out.println("進(jìn)來(lái)了~當(dāng)前樓層是"+this.on+" 我們的目標(biāo)是"+num+"層"); if(num==this.on) { System.out.println("您就在本層 開(kāi)門(mén)"); } else if(num0num11numthis.on) { for(int y=this.on;y=num;y--) { Thread th1 = new Thread(); if(y==num) { System.out.println("電梯到達(dá)~歡迎下次在做···"); this.on=num; } else { System.out.println("電梯在"+y+"層 馬上就到,請(qǐng)等待····"); try { th1.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } } } } else if(num0num11numthis.on) { for(int y=this.on;y=num;y++) { Thread th1 = new Thread(); if(y==num) { System.out.println("電梯到達(dá)~歡迎下次在做····"); this.on=num; } else { System.out.println("電梯在"+y+"層 馬上就到,請(qǐng)等待····"); try { th1.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } } } } } public static void main(String[] args) { dianti d = new dianti(); //模擬開(kāi)始 初始化是1層 首先我們?nèi)?0層 d.wai(1);//傳進(jìn)去的1表示我們是在1層按電梯準(zhǔn)備上 d.nei(10);//表示電梯到了 我們選擇了10層開(kāi)始上升 現(xiàn)在電梯停留在10層 d.wai(5);//在電梯還在10層停留的時(shí)候 5層有人使用 d.nei(1);//目標(biāo)是一層 //這個(gè)其實(shí)不完整 還需要加上很多判斷的 必然經(jīng)過(guò)每層的時(shí)候判斷是否有順路下的 //還有就是電梯在上升的時(shí)候經(jīng)過(guò)了2層到了3層 此時(shí)2層有人按 又該如何 自己試著去想一想解決方法 } }
標(biāo)題名稱:java電梯運(yùn)行代碼,java多線程電梯
網(wǎng)頁(yè)地址:http://chinadenli.net/article45/dsedphi.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站收錄、全網(wǎng)營(yíng)銷推廣、網(wǎng)站內(nèi)鏈、關(guān)鍵詞優(yōu)化、網(wǎng)站導(dǎo)航、網(wǎng)頁(yè)設(shè)計(jì)公司
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)