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 ...
随机推荐
- OC-SEL
SEL SEL对应方法的地址 _cmd代表当前方法 1. 方法的存储位置 每个类的方法列表都存储在类对象中 每个方法都有一个与之对应的SEL类型的对象 根据一个SEL对象就可以找到方法的地址,进而调 ...
- nanosleep() -- 更精确的延迟 -----一个使用用例
[常规] nanosleep() -- 更精确的延迟 [复制链接] beyes 4220 主题 5152 帖子 3万 积分 GROAD 曲径通幽,安觅芳踪. 积分 30607 发消息 电梯直达 ...
- eclipse的html代码辅助失效解决办法
Eclipse IDE : .xhtml code assist is not working for JSF tag By mkyong | September 6, 2010 | Viewed : ...
- windows下vmware10.0 安装centos7
centos7.0-1506, 1511, 是指2015年, 06月份, 11月份. 这是rhel ubuntu发布新版本的时间. centos7.0 只提供了64位的系统下载: x86_64: we ...
- linux shell中判断bash脚本输入的参数个数
看下面的一段程序. #!/bin/bash ]; then echo "参数个数为$#个" else echo "没有参数" fi
- 关于在windows上的wamp集成环境和xampp上安装mongo扩展
今天来学习下mongodb,在装PHP扩展的时候本来是一个很轻松的事情,结果并不是我想想的那么简单. 我的集成环境是xampp的php版本是5.6的x86.我开启了安全模式,所以我需要mongo时ts ...
- 自己用WordPress搭了个站点
这周买了台阿里云,用wordpress搭了个自己的站点,折腾了几天. 网站的网址是 http://www.smarteyeball.com/ ,取名慧眼网,宗旨是让大家发现新世界.
- Mastering Web Application Development with AngularJS 读书笔记(三)
第一章笔记 (三) 一.Factories factory 方法是创建对象的另一种方式,与service相比更灵活,因为可以注册可任何任意对象创造功能.例如: myMod.factory('notif ...
- 国内SEO如何过滤掉不良网络信息
对于站长们来说,首要任务就是和搜索引擎战斗,面对搜索引擎算法的不断更新,站长们也更加头疼.站长们都觉得,搜索引擎才是网站优化的"统治者",和谷歌优化相比,中国的SEO优化要复杂的多 ...
- lwfs指定特定目录输出
在特定节点启lwfs服务,输出特定的目录 在[root@devcpucs ~]# 节点启lwfs服务,输出指定目录/home/export/online1/systest/swcpucs 1.将gio ...