Design Elevator
From: https://discuss.leetcode.com/topic/89/write-elevator-program-using-event-driven-programming/9
We can divide into three main components:
User
- User presses the floor button (can be up or down direction) to summon the elevator.
- User presses the elevator button to go to the destination floor.
Button
- An elevator has buttons (ElevatorButton) inside allowing user to choose the destination floor.
- Each floor has two buttons (FloorButton) to summon the elevator to go up or down from that floor.
- When the user presses the button, it illuminates.
- When the elevator reaches the desired floor, the button stops illuminating.
- Calls placeRequest() to insert into the ElevatorRequest queue when button is pressed.
Elevator
- Open or close door.
- Moves up/down.
- Stores states such as direction (up/down), speed, currentFloor.
We need a queue to store all request, this can all be encapsulated in an ElevatorRequests class. When a user presses a button, this request has to be served and is added to the processing queue. Elevator requests can be scheduled using different scheduling algorithms. ElevatorController controls the elevator by giving it instructions such as move up/down, or start/shutdown. The elevator controller reads the next elevator request and serves it.
分析:
这个设计还可以,但是里面有些问题:
1. Controller 里还缺少process() 这样的方法,这个方法的实现应该是一个while loop, 每次执行玩一个request, 就从ElevatorRequest取下一个requet. 只要从ElevatorRequest返回的request不为空,就应该按照request的楼层前进。而且,Controller里不但有Elevator的reference, 也需要有ElevatorRequest对象的reference. 这两个reference 在Controller constructor里得到初始化。
2. Button 里需要有ElevatorRequest对象的索引。
3. Button里不需要有direction. CurrentFloor 和 destinFloor 就决定了direction. 在现实生活中也是只要的。
Design Elevator的更多相关文章
- Pair Project: Elevator Scheduler [电梯调度算法的实现和测试]
作业提交时间:10月9日上课前. Design and implement an Elevator Scheduler to aim for both correctness and performa ...
- 软件工程 --- Pair Project: Elevator Scheduler [电梯调度算法的实现和测试]
软件工程 --- Pair Project: Elevator Scheduler [电梯调度算法的实现和测试] 说明结对编程的优点和缺点. 结对编程的优点如下: 在独立设计.实现代码的过程中不 ...
- cf472B Design Tutorial: Learn from Life
B. Design Tutorial: Learn from Life time limit per test 1 second memory limit per test 256 megabytes ...
- Codeforces Round #270--B. Design Tutorial: Learn from Life
Design Tutorial: Learn from Life time limit per test 1 second memory limit per test 256 megabytes in ...
- Elevator poj3539
Elevator Time Limit: 4000MS Memory Limit: 65536K Total Submissions: 1072 Accepted: 287 Case Time ...
- BUAAOO P5-P7 Elevator Simulation
目录 Abstract Introduction Topic Request Elevator Analysis Reading Requests Coordinating Scheduling an ...
- SAP Process Integration - High Level ERP/Integration Process --- Cargill Process Concept Design
Customer Industry: Commercial off-the-shelf (COTS) application ,, Food Ingredients or Agricultural S ...
- UVALive 2949 Elevator Stopping Plan(二分 + 贪心)
ZSoft Corp. is a software company in GaoKe Hall. And the workers in the hall are very hard-working. ...
- POJ3539 Elevator
Time Limit: 4000MS Memory Limit: 65536KB 64bit IO Format: %lld & %llu Description Edward wor ...
随机推荐
- java中跳出if判断
今天学到的一点儿新东西一个if判断里面有好多东西,紧接着还有其他代码,不能使用return来结束这个if判断这时候,就需要这样: out:if (!"null".equals(re ...
- thinkphp的url地址区分大小写?
在默认情况下: 在访问url地址的时候, 其中的 Action类名 即: 模块名称 是区分大小写的. (只有模块名, 即控制器名称) 可以根据设置 'URL_CASE_INSENSITIVE' =&g ...
- Unity3D
一.安装配置 1.下载页面:http://unity3d.com/get-unity 分个人版本和专业版,个人版免费,但少了很多功能(主要是渲染相关,具体请看官方说明), 专业版是每月 75$ 或一次 ...
- MapReduce的MapTask任务的运行源码级分析
TaskTracker任务初始化及启动task源码级分析 这篇文章中分析了任务的启动,每个task都会使用一个进程占用一个JVM来执行,org.apache.hadoop.mapred.Child方法 ...
- Jquery实现滚动显示欢迎字幕效果
Jquery控制滚动显示欢迎字幕: 参考代码: <!DOCTYPE html> <html> <head> <title>Colin Marquee W ...
- VBA 实现批量excel文件复制
对于每天要将文件复制到其他多个路径 1 在test文件下新建3个子文件夹 test1,test2,test3 2 在test1下新建li01.xlsx,li02.xlsx,hua01.xlsx,hua ...
- PHP团队 编码规范 & 代码样式风格规范
一.基本约定 1.源文件 (1).纯PHP代码源文件只使用 <?php 标签,省略关闭标签 ?> : (2).源文件中PHP代码的编码格式必须是无BOM的UTF-8格式: (3).使用 U ...
- php 正则表达式的使用
要点:php正则表达式要用双引号,且要用“/ /”斜线做开始结束. 1.preg_match . preg_match_all 两者的区别:第一次匹配成功后就会停止匹配,如果要实现全部结果的匹配,即搜 ...
- maven之window安装
1.下载:apache-maven-3.3.9-bin.zip 2.解压下载的maven文件到任意指定文件夹 3.配置maven 右键“我的电脑” -> "属性" 在打开的属 ...
- Codeforces Round #340 Watering Flowers
题目: http://www.codeforces.com/contest/617/problem/C 自己感觉是挺有新意的一个题目, 乍一看挺难得(= =). 其实比较容易想到的一个笨办法就是:分别 ...