欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

傻瓜電梯Java代碼,電梯怎么編程

用java編一個電梯(二十樓)小程序怎么編?

這是我回答前幾天和你一樣想要的電梯程序 是單箱的 希望能幫助你 package bean; public class dianti { int on=1;//定義一個初始化樓層 初始化是在1層 //先從簡單的開始 我們先寫兩個方法 一個是在電梯外面方法 一個是在電梯內(nèi)部的方法 public void wai(int num)//外部方法 { if(num==this.on) { System.out.println("停留在本層 直接開門"); } else if(numthis.on) { Thread th = new Thread(); for(int i=this.on;i=num;i++) { if(i==num) { System.out.println("電梯到達~開門請進···"); this.on=num; } else { System.out.println("電梯在"+i+"層 馬上就到,請等待····"); try { th.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } } } } else if(num0numthis.on) { System.out.println("進來了" +num+" "+this.on); Thread th1 = new Thread(); for(int u=this.on;u=num;u--) { if(u==num) { System.out.println("電梯到達~開門請進···"); this.on=num; } else { System.out.println("電梯在"+u+"層 馬上就到,請等待····"); try { th1.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } } } } else { System.out.println("1111111111111"); } } //內(nèi)部方法 public void nei(int num) { System.out.println("進來了~當(dāng)前樓層是"+this.on+" 我們的目標(biāo)是"+num+"層"); if(num==this.on) { System.out.println("您就在本層 開門"); } else if(num0num11numthis.on) { for(int y=this.on;y=num;y--) { Thread th1 = new Thread(); if(y==num) { System.out.println("電梯到達~歡迎下次在做···"); this.on=num; } else { System.out.println("電梯在"+y+"層 馬上就到,請等待····"); 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("電梯到達~歡迎下次在做····"); this.on=num; } else { System.out.println("電梯在"+y+"層 馬上就到,請等待····"); try { th1.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } } } } } public static void main(String[] args) { dianti d = new dianti(); //模擬開始 初始化是1層 首先我們?nèi)?0層 d.wai(1);//傳進去的1表示我們是在1層按電梯準備上 d.nei(10);//表示電梯到了 我們選擇了10層開始上升 現(xiàn)在電梯停留在10層 d.wai(5);//在電梯還在10層停留的時候 5層有人使用 d.nei(1);//目標(biāo)是一層 //這個其實不完整 還需要加上很多判斷的 必然經(jīng)過每層的時候判斷是否有順路下的 //還有就是電梯在上升的時候經(jīng)過了2層到了3層 此時2層有人按 又該如何 自己試著去想一想解決方法 } }

創(chuàng)新互聯(lián)擁有一支富有激情的企業(yè)網(wǎng)站制作團隊,在互聯(lián)網(wǎng)網(wǎng)站建設(shè)行業(yè)深耕10多年,專業(yè)且經(jīng)驗豐富。10多年網(wǎng)站優(yōu)化營銷經(jīng)驗,我們已為成百上千中小企業(yè)提供了成都網(wǎng)站設(shè)計、成都網(wǎng)站建設(shè)、外貿(mào)網(wǎng)站建設(shè)解決方案,按需制作網(wǎng)站,設(shè)計滿意,售后服務(wù)無憂。所有客戶皆提供一年免費網(wǎng)站維護!

利用java編寫代碼實現(xiàn)如下功能,需要全部代碼

很簡單的應(yīng)用,為了節(jié)省字數(shù),代碼注釋我就不加了

首先是顯示層,LoinWindow:

import?java.awt.FlowLayout;

import?java.awt.GridBagConstraints;

import?java.awt.GridBagLayout;

import?java.awt.GridLayout;

import?java.awt.event.ActionEvent;

import?java.awt.event.ActionListener;

import?java.awt.event.FocusEvent;

import?java.awt.event.FocusListener;

import?javax.swing.JButton;

import?javax.swing.JFrame;

import?javax.swing.JLabel;

import?javax.swing.JOptionPane;

import?javax.swing.JPanel;

import?javax.swing.JTextField;

import?javax.swing.border.EmptyBorder;

public?class?LoinWindow?extends?JFrame?implements?ActionListener,?FocusListener?{

private?JPanel?mainPanel,?namePanel,?btnPanel;

private?JTextField?tfName,?tfPsd;

private?JButton?btnLogin,?btnCancel;

private?static?final?int?WIDTH?=?300;

private?static?final?int?HEIGHT?=?200;

private?LoginService?service?=?new?LoginService();

public?LoinWindow()?{

super("登錄窗體");

}

public?void?launch()?{

setSize(WIDTH,?HEIGHT);

setVisible(true);

setDefaultCloseOperation(EXIT_ON_CLOSE);

GridLayout?mainLayout?=?new?GridLayout(2,?1);

mainLayout.setVgap(10);

mainPanel?=?new?JPanel(mainLayout);

GridBagLayout?nameLayout?=?new?GridBagLayout();

namePanel?=?new?JPanel(nameLayout);

namePanel.setBorder(new?EmptyBorder(10,?10,?10,?10));

JLabel?nameLabel?=?new?JLabel("姓名:");

tfName?=?new?JTextField();

JLabel?psdLabel?=?new?JLabel("密碼:");

tfPsd?=?new?JTextField();

JLabel?blank?=?new?JLabel("?");

namePanel.add(nameLabel);

namePanel.add(tfName);

namePanel.add(blank);

namePanel.add(psdLabel);

namePanel.add(tfPsd);

GridBagConstraints?s?=?new?GridBagConstraints();

s.fill?=?GridBagConstraints.BOTH;

s.gridwidth?=?1;

s.weightx?=?0;

s.weighty?=?0;

nameLayout.setConstraints(nameLabel,?s);

s.gridwidth?=?0;

s.weightx?=?1;

s.weighty?=?0;

nameLayout.setConstraints(tfName,?s);

s.gridwidth?=?0;

s.weightx?=?4;

s.weighty?=?0;

nameLayout.setConstraints(blank,?s);

s.gridwidth?=?1;

s.weightx?=?0;

s.weighty?=?0;

nameLayout.setConstraints(psdLabel,?s);

s.gridwidth?=?3;

s.weightx?=?1;

s.weighty?=?0;

nameLayout.setConstraints(tfPsd,?s);

FlowLayout?btnLayout?=?new?FlowLayout();

btnLayout.setAlignment(FlowLayout.CENTER);

btnPanel?=?new?JPanel(btnLayout);

btnLogin?=?new?JButton("確定");

btnCancel?=?new?JButton("取消");

btnPanel.add(btnLogin);

btnPanel.add(btnCancel);

btnCancel.addActionListener(this);

btnLogin.addActionListener(this);

mainPanel.add(namePanel);

mainPanel.add(btnPanel);

setContentPane(mainPanel);

tfName.addFocusListener(this);

tfPsd.addFocusListener(this);

pack();

setSize(WIDTH,?HEIGHT);

setLocationRelativeTo(null);

}

@Override

public?void?actionPerformed(ActionEvent?e)?{

Object?source?=?e.getSource();

if(source?==?btnCancel)?{

System.exit(0);

}?else?if(source?==?btnLogin)?{

String?username?=?tfName.getText();

String?password?=?tfPsd.getText();

boolean?success?=?service.login(username,?password);

if(success)?{

warn("成功",?"登錄成功!");

}?else?{

warn("失敗",?"您輸入的用戶名或密碼錯誤?!");

}

}

}

@Override

public?void?focusGained(FocusEvent?arg0)?{

}

@Override

public?void?focusLost(FocusEvent?e)?{

Object?source?=?e.getSource();

if(source?==?tfName)?{

String?username?=?tfName.getText();

try?{

service.matchUsername(username);

}?catch?(LoginException?e1)?{

warn("驗證錯誤",?e1.getMessage());

}

}?else?if(source?==?tfPsd)?{

String?password?=?tfPsd.getText();

try?{

service.matchPassword(password);

}?catch?(LoginException?e1)?{

warn("驗證錯誤",?e1.getMessage());

}

}

}

private?void?warn(String?title,?String?msg)?{

JOptionPane.showMessageDialog(null,?msg,?title,?JOptionPane.INFORMATION_MESSAGE);

}

public?static?void?main(String[]?args)?{

new?LoinWindow().launch();

}

}

然后是模型層:LoginDao

public?class?LoginDao?{

public?boolean?login(String?username,?String?password)?{

if(username.equals("admin")??password.equals("12345"))?{

return?true;

}

return?false;

}

}

LoginService

import?java.util.regex.Pattern;

public?class?LoginService?{

private?static?final?Pattern?LOGIN_PATTERN?=?Pattern.compile("[a-zA-Z]+");

private?static?final?Pattern?PASSWORD_PATTERN?=?Pattern.compile("[1-9]+");

private?LoginDao?dao?=?new?LoginDao();

public?boolean?matchUsername(String?username)?throws?LoginException?{

if(null?==?username?||?username.isEmpty())?{

return?false;

}

if(!LOGIN_PATTERN.matcher(username).matches())?{

throw?new?LoginException("您輸入的用戶名不合法,請輸入英文!");

}

return?true;

}

public?boolean?matchPassword(String?password)?throws?LoginException?{

if(null?==?password?||?password.isEmpty())?{

return?false;

}

if(!PASSWORD_PATTERN.matcher(password).matches())?{

throw?new?LoginException("您輸入的密碼不合法,請輸入數(shù)字!");

}

return?true;

}

public?boolean?login(String?username,?String?password)?{

if(null?==?username?||?username.isEmpty())?{

return?false;

}

if(null?==?password?||?password.isEmpty())?{

return?false;

}

if(!dao.login(username,?password))?{

return?false;

}

return?true;

}

}

LoginException

public?class?LoginException?extends?Exception?{

public?LoginException(String?arg0)?{

super(arg0);

}

}

不知道分層設(shè)計思想是不是我想的這樣

電梯的工作程序代碼?用JAVA語言可以嗎?可以的話速求!

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

但是一般直接和硬件交互 一般用PLC

求一個簡單又有趣的JAVA小游戲代碼

具體如下:

連連看的小源碼

package Lianliankan;

import javax.swing.*;

import java.awt.*;

import java.awt.event.*;

public class lianliankan implements ActionListener

{

JFrame mainFrame; //主面板

Container thisContainer;

JPanel centerPanel,southPanel,northPanel; //子面板

JButton diamondsButton[][] = new JButton[6][5];//游戲按鈕數(shù)組

JButton exitButton,resetButton,newlyButton; //退出,重列,重新開始按鈕

JLabel fractionLable=new JLabel("0"); //分數(shù)標(biāo)簽

JButton firstButton,secondButton; //

分別記錄兩次62616964757a686964616fe59b9ee7ad9431333335326239被選中的按鈕

int grid[][] = new int[8][7];//儲存游戲按鈕位置

static boolean pressInformation=false; //判斷是否有按鈕被選中

int x0=0,y0=0,x=0,y=0,fristMsg=0,secondMsg=0,validateLV; //游戲按鈕的位置坐標(biāo)

int i,j,k,n;//消除方法控制

代碼(code)是程序員用開發(fā)工具所支持的語言寫出來的源文件,是一組由字符、符號或信號碼元以離散形式表示信息的明確的規(guī)則體系。

對于字符和Unicode數(shù)據(jù)的位模式的定義,此模式代表特定字母、數(shù)字或符號(例如 0x20 代表一個空格,而 0x74 代表字符“t”)。一些數(shù)據(jù)類型每個字符使用一個字節(jié);每個字節(jié)可以具有 256 個不同的位模式中的一個模式。

在計算機中,字符由不同的位模式(ON 或 OFF)表示。每個字節(jié)有 8 位,這 8 位可以有 256 種不同的 ON 和 OFF 組合模式。對于使用 1 個字節(jié)存儲每個字符的程序,通過給每個位模式指派字符可表示最多 256 個不同的字符。2 個字節(jié)有 16 位,這 16 位可以有 65,536 種唯一的 ON 和 OFF 組合模式。使用 2 個字節(jié)表示每個字符的程序可表示最多 65,536 個字符。

單字節(jié)代碼頁是字符定義,這些字符映射到每個字節(jié)可能有的 256 種位模式中的每一種。代碼頁定義大小寫字符、數(shù)字、符號以及 !、@、#、% 等特殊字符的位模式。每種歐洲語言(如德語和西班牙語)都有各自的單字節(jié)代碼頁。

雖然用于表示 A 到 Z 拉丁字母表字符的位模式在所有的代碼頁中都相同,但用于表示重音字符(如"é"和"á")的位模式在不同的代碼頁中卻不同。如果在運行不同代碼頁的計算機間交換數(shù)據(jù),必須將所有字符數(shù)據(jù)由發(fā)送計算機的代碼頁轉(zhuǎn)換為接收計算機的代碼頁。如果源數(shù)據(jù)中的擴展字符在接收計算機的代碼頁中未定義,那么數(shù)據(jù)將丟失。

如果某個數(shù)據(jù)庫為來自許多不同國家的客戶端提供服務(wù),則很難為該數(shù)據(jù)庫選擇這樣一種代碼頁,使其包括所有客戶端計算機所需的全部擴展字符。而且,在代碼頁間不停地轉(zhuǎn)換需要花費大量的處理時間。

用Java編寫程序,設(shè)計一個模擬電梯運行的類

最佳答案代碼如下:

public class ElevatorModel implenent ElevatorModelListener{

ElevatorShaft elevatorShaft;//電梯車箱

Floor firstFloor;

Floor secondFloor;

public void addPerson(Person person);

//實現(xiàn)ElevatorModelListener接口的所有方法

}

public abstract class Location{

String locationName;//可能占據(jù)的三個位置firstFloor; secondFloor;elevator中的其中一個位置。

public Button getButton();

public Door getDoor();

}

public class Floor extends Location{

public Floor(String firstFloor,String secondFloor);

public Button getButton();//具體實現(xiàn)

public Door getDoor();//具體實現(xiàn)

public ElevatorShaft getElevatorShaft();

}

public class Door implenent ElevatorMoveListener{

boolean open;//門是開的關(guān)的

public void openDoor();//開門

public viod clossDoor();//關(guān)門

}

public class Button implenent ElevatorMoveListener{

boolean pressed;

public void pressButton();//按下按鈕

public void resetButton();//釋放按鈕

public void elevatorArrived();//電梯到來

}

public class ElevatorShaft{//電梯乘箱

Elevator elevator;//電梯

Button firstFloorButton,secondFloorButton;//出發(fā)層的按鈕和到達層的按鈕 Door firstFloorDoor,secondFloorDoor;//出發(fā)的門和到達的門

Light firstFloorLight,secondFloorLight;//燈

//監(jiān)聽器

DoorListener doorListener;

ButtonListener buttonListener;

LightListener ligthListener;

BellListener bellListener;

ElevatorMoveListener elevatorMoveListener;

Set set;

}

public class Light implenent ElevatorMoveListener{

boolean lightOn;//代表燈的狀態(tài),亮或滅

public void turnOnLight();

public void turnOffLight();

public void elevatorDeparted();//具體實現(xiàn)

public void elevatorArrived();//具體實現(xiàn)

}

public class Bell implenent ElevatorMoveListener{

public void ringBell();

public void elevatorDeparted();//具體實現(xiàn)

public void elevatorArrived();//具體實現(xiàn)

}

public class Elevator extends Location implenets

ButtonListener,DoorListener,BellListener,Runable

{//電梯乘箱

boolean moving;

boolean summoned;//描述Elevator是在移動還是已經(jīng)補召喚

Floor currentFloor;//當(dāng)前正在提供服務(wù)的Floor

Floor destinationFloor ; //代表將要到達的Floor

Button elevatorButton;

Door elevatorDoor;

Bell bell;

public void run();// 實現(xiàn)

public void requestElevator();//請求Elevator并產(chǎn)生排隊請求。 }

public class Person extends Thread{

Location類對象(或是位于Floor上,或是出處在Elevator中); int ID;

boolean moving;

public void run();//具體實現(xiàn)

public void enterAndRideElevator();

}

求java的代碼!

public?class?Room?{

private?int?roomID;

private?double?roomArea;

private?String?address;

public?int?getRoomID()?{

return?roomID;

}

public?void?setRoomID(int?roomID)?{

this.roomID?=?roomID;

}

public?double?getRoomArea()?{

return?roomArea;

}

public?void?setRoomArea(double?roomArea)?{

this.roomArea?=?roomArea;

}

public?String?getAddress()?{

return?address;

}

public?void?setAddress(String?address)?{

this.address?=?address;

}

public?Room(){};

public?Room(int?roomID){

this.roomID?=?roomID;

};

public?Room(int?roomID,?double?roomArea){

this.roomID?=?roomID;

this.roomArea?=?roomArea;

}

public?Room(int?roomID,?double?roomArea,?String?address){

this.roomID?=?roomID;

this.roomArea?=?roomArea;

this.address?=?address;

}

public?String?getDetails()?{

return?"Room?[房號:"?+?roomID?+?",?面積:"?+?roomArea?+?",?地址:"?+?address?+?"]";

}

public?static?void?main(String[]?args)?{

Room?room1?=?new?Room();

Room?room2?=?new?Room(1);

Room?room3?=?new?Room(2,?100);

Room?room4?=?new?Room(3,?120,?"china");

System.out.println(room1.getDetails()?+?"\r\n"?+?room2.getDetails()?+?"\r\n"?+?room3.getDetails()?+?"\r\n"?+?room4.getDetails());

}

}

這么簡單的不能自己寫嗎

新聞名稱:傻瓜電梯Java代碼,電梯怎么編程
轉(zhuǎn)載來于:http://chinadenli.net/article45/dsggsei.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供微信公眾號商城網(wǎng)站自適應(yīng)網(wǎng)站標(biāo)簽優(yōu)化網(wǎng)站導(dǎo)航企業(yè)建站

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

成都定制網(wǎng)站建設(shè)