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 ...
随机推荐
- Enabling and Mounting NFS on CoreOS
http://blog.scottlowe.org/2015/02/20/config-mount-nfs-coreos/ #cloud-config write-files: - path: /et ...
- java中的各个数据结构区别
ArrayList 和Vector是采用数组方式存储数据,此数组元素数大于实际存储的数据以便增加和插入元素,都允许直接序号索引元素,但是插入数据要设计到数组元素移动等内存操作,所以索引数据快插入数据慢 ...
- phpcms v9 0day
index.php?m=member&c=index&a=login 后缀 username=phpcms&password=123456%26username%3d%2527 ...
- http的六种请求方法
1.get: GET可以说是最常见的了,它本质就是发送一个请求来取得服务器上的某一资源.资源通过一组HTTP头和呈现数据(如HTML文本,或者图片或者视频等)返回给客户端.GET请求中,永远不会包含呈 ...
- 未能正确加载“Microsoft.VisualStudio.Editor.Implementation.EditorPackage”包
解决方案: 关掉VS2012... "Microsoft Visual Studio 2012"->"Visual Studio Tools"->& ...
- Map静态键值对
private final static Map<String,String> map = new HashMap<String, String>(); static { // ...
- jquery报错Uncaught ReferenceError: $ is not defined
- Storm:最火的流式处理框架
伴随着信息科技日新月异的发展,信息呈现出爆发式的膨胀,人们获取信息的途径也更加多样.更加便捷,同时对于信息的时效性要求也越来越高.举个搜索场景中的例子,当一个卖家发布了一条宝贝信息时,他希望的当然是这 ...
- 删除多个Safari书签
Safari 的书签多了,删除起来很麻烦,可以先选中所有书签,然后再按"Command+Delete",就可以全部删除了.
- 我常用的eclipse快捷键
重写父类方法:右键点击, 进source,进override/implement 单行注释(或多行注释) Ctrl+/ 文档注释:shift+alt+J 整块注释: Ctrl+shift+/ 取消整块 ...