资源简介
北航OO课的作业代码,从电梯到出租车,你想要的都在里面。注释充足,供有需要的同学参考(切勿抄袭哦~)
代码片段和文件信息
package Elevator;
import java.lang.reflect.Array;
import java.util.ArrayList;
public class ALSSimulator extends Simulator{
protected ArrayList elevatorButtonRequestList; //电梯内按钮存储请求所用数组
protected ArrayList floorButtonRequestList; //楼层按钮存储请求所用数组,共20个,以2个为单位,前一个代表上按钮,后一个代表下按钮
public ALSSimulator(RequestQueue requestQueue) {
super(requestQueue);
Request tempRequest;
floorButtonRequestList = new ArrayList<>();
for (int i = 0; i < 2 * floors.length; i++) {
tempRequest = new Request(“FR“ 0);
floorButtonRequestList.add(null);
}
elevatorButtonRequestList = new ArrayList<>();
for (int i = 0; i < floors.length; i++) {
tempRequest = new Request(“ER“ 0);
elevatorButtonRequestList.add(null);
}
}
//遍历请求队列检查当前时间是否有请求有则按下对应按钮,返回值为获取到的请求个数
public int checkCurrentRequestCount(int lastRequestIndex) {
int currentRequestIndex = lastRequestIndex + 1;
//请求队列已经读完
if (currentRequestIndex == this.requestList.size()) {
return 0;
}
Request currentRequest = this.requestList.get(currentRequestIndex);
double currentRequestTime = currentRequest.getRequestTime();
int targetFloor;
int loopCount = 0;
int tempArg;
while (currentRequestTime == this.time) {
if (currentRequest.getType().equals(“ER“)) { //该请求为ER类请求
targetFloor = ((ElevatorRequest)currentRequest).getTargetFloor();
if (this.elevator.pressButton(targetFloor)) { //按按钮并判断是否被按下
currentRequest.setRequestRank(loopCount); //设置同时间请求的先后次序
this.elevatorButtonRequestList.set(targetFloor - 1 (ElevatorRequest)currentRequest); //将请求存入按钮
}else{
System.out.println(“Request is ignored for duplication: “ + currentRequest); //输出因为重复而被忽略的请求
}
}else{ //该请求为FR类请求
targetFloor = ((FloorRequest)currentRequest).getFloorNumber();
//用tempArg代表上或者下
if (((FloorRequest)currentRequest).getUpOrDown() == 1) {
tempArg = 0;
}else{
tempArg = 1;
}
if ((this.floors[targetFloor - 1].getUpButtonIsPressed() && ((FloorRequest)currentRequest).getUpOrDown() == 1) ||
(this.floors[targetFloor - 1].getDownButtonIsPressed() && ((FloorRequest)currentRequest).getUpOrDown() == -1)) {
System.out.println(“Request is ignored for duplication: “ + currentRequest); //输出因为重复而被忽略的请求
}else{
if (tempArg == 0) {
this.floors[targetFloor - 1].pressUpButton(); //按下向上按钮
}else{
this.floors[targetFloor - 1].pressDownButton(); //按下向下按钮
}
currentRequest.setRequestRank(loopCount); //设置同时间请求的先后次序
this.floorButtonRequestList.set(2 * (targetFloor - 1) + tempArg (FloorRequest)currentRequest); //将请求存入按钮
}
}
currentRequestIndex++;
if (currentRequestIndex == this.requestList.size()) {
break;
}
currentRequest = (Request)this.requestList.get(currentRequestIndex);
currentRequestTime = currentRequest.getRequestTime();
loopCount++;
}
return (currentRequestIndex - lastRequestIndex - 1);
}
//判断电梯内是否有同趋势请求
public boolean
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2017-11-22 05:13 Java-Exercise-master\
文件 10244 2017-11-22 05:13 Java-Exercise-master\.DS_Store
文件 65 2017-11-22 05:13 Java-Exercise-master\.gitattributes
文件 11 2017-11-22 05:13 Java-Exercise-master\.gitignore
目录 0 2017-11-22 05:13 Java-Exercise-master\Elevator3\
文件 6148 2017-11-22 05:13 Java-Exercise-master\Elevator3\.DS_Store
文件 295 2017-11-22 05:13 Java-Exercise-master\Elevator3\.classpath
目录 0 2017-11-22 05:13 Java-Exercise-master\Elevator3\.idea\
文件 232 2017-11-22 05:13 Java-Exercise-master\Elevator3\.idea\kotlinc.xm
文件 695 2017-11-22 05:13 Java-Exercise-master\Elevator3\.idea\misc.xm
文件 258 2017-11-22 05:13 Java-Exercise-master\Elevator3\.idea\modules.xm
文件 17844 2017-11-22 05:13 Java-Exercise-master\Elevator3\.idea\workspace.xm
文件 368 2017-11-22 05:13 Java-Exercise-master\Elevator3\.project
目录 0 2017-11-22 05:13 Java-Exercise-master\Elevator3\.settings\
文件 587 2017-11-22 05:13 Java-Exercise-master\Elevator3\.settings\org.eclipse.jdt.core.prefs
文件 437 2017-11-22 05:13 Java-Exercise-master\Elevator3\Elevator3.iml
文件 249320 2017-11-22 05:13 Java-Exercise-master\Elevator3\Readme(UnitTest).docx
文件 76669 2017-11-22 05:13 Java-Exercise-master\Elevator3\Readme.docx
目录 0 2017-11-22 05:13 Java-Exercise-master\Elevator3\bin\
文件 6148 2017-11-22 05:13 Java-Exercise-master\Elevator3\bin\.DS_Store
目录 0 2017-11-22 05:13 Java-Exercise-master\Elevator3\bin\Elevator\
文件 8287 2017-11-22 05:13 Java-Exercise-master\Elevator3\bin\Elevator\ALSSimulator.class
文件 5132 2017-11-22 05:13 Java-Exercise-master\Elevator3\bin\Elevator\Elevator.class
文件 224 2017-11-22 05:13 Java-Exercise-master\Elevator3\bin\Elevator\ElevatorInterface.class
文件 1056 2017-11-22 05:13 Java-Exercise-master\Elevator3\bin\Elevator\ElevatorRequest.class
文件 1645 2017-11-22 05:13 Java-Exercise-master\Elevator3\bin\Elevator\ElevatorTest.class
文件 3012 2017-11-22 05:13 Java-Exercise-master\Elevator3\bin\Elevator\ElevatorThread.class
文件 1735 2017-11-22 05:13 Java-Exercise-master\Elevator3\bin\Elevator\Floor.class
文件 1452 2017-11-22 05:13 Java-Exercise-master\Elevator3\bin\Elevator\FloorRequest.class
文件 5529 2017-11-22 05:13 Java-Exercise-master\Elevator3\bin\Elevator\InputHandler.class
文件 795 2017-11-22 05:13 Java-Exercise-master\Elevator3\bin\Elevator\InputThread.class
............此处省略293个文件信息
- 上一篇:电子书批量搜索软件
- 下一篇:IEC61850服务端模拟软件 V1.0
相关资源
- 最新 guns v5.1 文档
- Google Play结算库V2.0.3 接入
- 《Spring Boot实战》源代码
- spring-boot-reference.pdf
- 北航矩阵论学习笔记
- Drools技术指南.rar
- Drools技术指南.pdf
- opendaylight cookbook
-
Linux Shell sc
ripting Cookbook - Third Edit - Bootstrap学习
- 北航检测估计与调制理论讲义
- odoojs教程书籍.pdf
- Agile! - The Good the Hype and the Ugly
- hadoop API
- Hadoop编程操作 高性能云计算
- big data analysis
- dlib-19.4.0-cp35.whl Windows64位 不用boos
- springboot实战源码
- 面向对象软件工程-第三版英文版
- 数帅IOVST Tools
- TI DSP6000系列boot详解
- envi fx使用手册
- qt-vs-tools-msvc2015-2.0.0
- Hadoop安全:大数据平台隐私保护.pdf
- Angulr– Bootstrap Admin Web App with Angular
- booktool.zip(x86汇编语言-从实模式到保
- spring boot + plupload实现大文件断点续传
- mac10.9版本的vmtools安装工具
- Kali Linux Cookbook 无水印pdf
- The Boost Graph Library 无水印pdf
评论
共有 条评论