• 大小: 3.59MB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2023-11-14
  • 语言: 其他
  • 标签: 北航  面向对象  OO  

资源简介

北航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.xml
     文件         695  2017-11-22 05:13  Java-Exercise-master\Elevator3\.idea\misc.xml
     文件         258  2017-11-22 05:13  Java-Exercise-master\Elevator3\.idea\modules.xml
     文件       17844  2017-11-22 05:13  Java-Exercise-master\Elevator3\.idea\workspace.xml
     文件         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个文件信息

评论

共有 条评论