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 ...
随机推荐
- trace enabled
<system.web> <trace enabled="true" localOnly="true" pageOutput="tr ...
- django,python,svn_web
- Struts2验证框架实例
今天写了个Struts验证框架的实例,总算把验证框架弄清楚了. 上一篇Struts实例的action没有继承ActionSupport类,虽然也可以实现action的功能,但是却不能应用Struts提 ...
- 整理的mysql优化内容
1,当只要一行数据时使用 LIMIT 1如果明确只取一条数据,要加上limit 1; 2,避免 SELECT *,根据需要获取字段应该养成一个需要什么就取什么的好的习惯. 3,使用 ENUM 而不是 ...
- Android 开发
1.Activity 子类会重载一个 protected void onCreate(Bundle savedInstanceState) { ... } 方法,其中 savedInstanceSta ...
- R入门-第一次写了一个完整的时间序列分析代码
纪念一下,在心心念念想从会计本科转为数据分析师快两年后,近期终于迈出了使用R的第一步,在参考他人的例子前提下,成功写了几行代码.用成本的角度来说,省去了部门去买昂贵的数据分析软件的金钱和时间,而对自己 ...
- maven 项目配置
创建java web的maven项目方法有两种,一是先创建maven项目,再选择jdk 和 dynamic web 运行环境 ,二是创建java项目,然后转化为maven项目 1.将普通java项目转 ...
- 一个C#的与web服务器交互的HttpClient类
using System; using System.Collections.Generic; using System.IO; using System.Text; using System.Net ...
- jquery左右滑动效果的实现
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- LVS NAT模式
LVS-NAT 三台虚拟机都是centos 6.5 关闭防火墙和selinux 角色 IP地址 备注 LVS负载调度器 eth0:192.168.119.128(内网) eth1:192.168.94 ...