电梯代码java 电梯代码er什么意思

JAVA 电梯运行管理程序public static void main(String[] args) {
/*Lianxi1 lx = new Lianxi1();
lx.method();*/
boolean flag =new Lianxi1().byLift();
if(flag == true){
System.out.println("没有地下室 开门");
}else
System.out.println("关门");
}
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));//楼层数 1-5随机
switch (num){
case 1000:
System.out.println("超重,发出警报 无法关门");
break;
default:
System.out.println("电梯关门");
break;
}
//选择楼层 1-5返回true 关门
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;
}
}
用Java编写程序 , 设计一个模拟电梯运行的类【电梯代码java 电梯代码er什么意思】最佳答案代码如下:
public class ElevatorModel implenent ElevatorModelListener{
ElevatorShaft elevatorShaft;//电梯车箱
Floor firstFloor;
Floor secondFloor;
public void addPerson(Person person);
//实现ElevatorModelListener接口的所有方法
}
public abstract class Location{
String locationName;//可能占据的三个位置firstFloor; secondFloor;elevator中的其中一个位置 。
public Button getButton();
public Door getDoor();
}
public class Floor extends Location{
public Floor(String firstFloor,String secondFloor);
public Button getButton();//具体实现
public Door getDoor();//具体实现
public ElevatorShaft getElevatorShaft();
}
public class Door implenent ElevatorMoveListener{
boolean open;//门是开的关的
public void openDoor();//开门
public viod clossDoor();//关门
}
public class Button implenent ElevatorMoveListener{
boolean pressed;
public void pressButton();//按下按钮
public void resetButton();//释放按钮
public void elevatorArrived();//电梯到来
}
public class ElevatorShaft{//电梯乘箱
Elevator elevator;//电梯
Button firstFloorButton,secondFloorButton;//出发层的按钮和到达层的按钮 Door firstFloorDoor,secondFloorDoor;//出发的门和到达的门
Light firstFloorLight,secondFloorLight;//灯
//监听器
DoorListenerdoorListener;
ButtonListenerbuttonListener;
LightListenerligthListener;
BellListenerbellListener;
ElevatorMoveListenerelevatorMoveListener;
Setset;
}
public class Light implenent ElevatorMoveListener{
boolean lightOn;//代表灯的状态 , 亮或灭
public void turnOnLight();
public void turnOffLight();
public void elevatorDeparted();//具体实现
public void elevatorArrived();//具体实现
}
public class Bell implenent ElevatorMoveListener{
public void ringBell();
public void elevatorDeparted();//具体实现
public void elevatorArrived();//具体实现
}
public class Elevator extends Location implenets
ButtonListener,DoorListener,BellListener,Runable
{//电梯乘箱
boolean moving;
boolean summoned;//描述Elevator是在移动还是已经补召唤
Floor currentFloor;//当前正在提供服务的Floor
Floor destinationFloor ; //代表将要到达的Floor
Button elevatorButton;
Door elevatorDoor;
Bell bell;
public void run();// 实现
public void requestElevator();//请求Elevator并产生排队请求 。}
public class Person extends Thread{
Location类对象(或是位于Floor上 , 或是出处在Elevator中); int ID;

推荐阅读