Careercup - Microsoft面试题 - 6314866323226624
2014-05-11 05:29
原题:
- Design remote controller for me.
题目:设计一个遥控器。
解法:遥控什么?什么遥控?传统的红外线信号吗?我只能随便说说思路吧。不知道这算什么类型的面试题,真遇到的话也算是倒了霉了。想了半天恍然大悟:原来是考察设计模式。查了相关资料后发现命令模式比较符合题意,所以就依葫芦画瓢写了个例子。
代码:
- // http://www.careercup.com/question?id=6366101810184192
- interface ICommand {
- public abstract void execute();
- }
- public class PowerOnCommand implements ICommand {
- @Override
- public void execute() {
- // TODO Auto-generated method stub
- System.out.println("Power on.");
- }
- }
- public class PowerOffCommand implements ICommand {
- @Override
- public void execute() {
- // TODO Auto-generated method stub
- System.out.println("Power off.");
- }
- }
- import java.util.Vector;
- public class RemoteController {
- private Vector<ICommand> buttons;
- private String[] configuration = {"PowerOnCommand", "PowerOffCommand"};
- public RemoteController() {
- // TODO Auto-generated constructor stub
- buttons = new Vector<ICommand>();
- for (String commandType : configuration) {
- try {
- try {
- buttons.add((ICommand) Class.forName(commandType).newInstance());
- } catch (InstantiationException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (IllegalAccessException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- } catch (ClassNotFoundException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- }
- public void push(int commandIndex) {
- try {
- buttons.elementAt(commandIndex).execute();
- } catch (ArrayIndexOutOfBoundsException e) {
- // TODO: handle exception
- }
- }
- }
Careercup - Microsoft面试题 - 6314866323226624的更多相关文章
- Careercup - Microsoft面试题 - 6366101810184192
2014-05-10 22:30 题目链接 原题: Design database locks to allow r/w concurrency and data consistency. 题目:设计 ...
- Careercup - Microsoft面试题 - 24308662
2014-05-12 07:31 题目链接 原题: I have heard this question many times in microsoft interviews. Given two a ...
- Careercup - Microsoft面试题 - 5700293077499904
2014-05-12 00:02 题目链接 原题: For a given map (ie Bing map) given longitude/latitude/ how would you desi ...
- Careercup - Microsoft面试题 - 5204967652589568
2014-05-11 23:57 题目链接 原题: identical balls. one ball measurements ........ dead easy. 题目:9个看起来一样的球,其中 ...
- Careercup - Microsoft面试题 - 5175246478901248
2014-05-11 23:52 题目链接 原题: design an alarm clock for a deaf person. 题目:为聋人设计闹钟? 解法:聋人听不见,那么闪光.震动都可行.睡 ...
- Careercup - Microsoft面试题 - 5718181884723200
2014-05-11 05:55 题目链接 原题: difference between thread and process. 题目:请描述进程和线程的区别. 解法:操作系统理论题.标准答案在恐龙书 ...
- Careercup - Microsoft面试题 - 5173689888800768
2014-05-11 05:21 题目链接 原题: Complexity of a function: int func_fibonacci ( int n) { ) { return n; } el ...
- Careercup - Microsoft面试题 - 6282862240202752
2014-05-11 03:56 题目链接 原题: Given an integer array. Perform circular right shift by n. Give the best s ...
- Careercup - Microsoft面试题 - 5428361417457664
2014-05-11 03:37 题目链接 原题: You have three jars filled with candies. One jar is filled with banana can ...
随机推荐
- 音乐社交APP源码 V1.1
1.关于音乐曲库,对接的是百度音乐,会自动随搜索链接百度曲库2.便捷聊天,采用xmpp基本架构.3.加入和整理了群聊天.4.分布式聊天,喜欢该专辑直接进入聊天,喜欢该音乐的进入聊天.5.采用兴趣社交和 ...
- SMTP sendMail 失败解决办法
If you are seeing messages like this in your message log when running a process through the process ...
- [原创] 初识Agile/CMMI/Scrum
一.背景介绍 在朋友(aehyok)的建议下,初步去了解Visual Studio Online,简称VS Online(即原来的 Team Foundation Service,简称TFS) VS ...
- C#中补0
C#中补0 编写人:CC阿爸 2014-3-16 首先先增加两个左补齐又补齐的函数 #region 该函数动态添加空格,对齐小票 public string AddSpace(string text ...
- [Redis] RDB & AOF
http://my.oschina.net/davehe/blog/174662 rdb - 存在dump.rdb 的二进制文件中 dump 整个db, 数据多的时候,不合适频繁保存,保存的时间间隔应 ...
- HBase分布式安装
安装HBase之前需要先安装Hadoop,因为HBase是运行在Hadoop集群上的.安装Hadoop可以参照http://www.cnblogs.com/stGeekpower/p/3307289. ...
- 【转】Spark性能测试报告
RDD可以很好地适用于支持数据并行的批量分析应用,包括数据挖掘,机器学习,图算法等,因为这些程序通常都会在很多记录上执行相同的操作.RDD不太适合那些异步更新共享状态的应用,例如并行web爬行器.因此 ...
- Laravel 5 基础(十一)- Eloquent 关系
一个用户可能有多个文章,一个文章是某个用户书写的,这就是关系.同样文章中可能包含多个 TAG,而一个 TAG 可能关联多个文章. 在项目中,我们已经有了 User.php,也就是用户模型,查看一下,相 ...
- 【原创】小白学jquery Mobile《构建跨平台APP:jQuery Mobile移动应用实战》连载五(给按钮加图标)
在范例5-4所使用的导航栏中,已经为按钮加入了图标的样式,但是当时并没有介绍按钮的图标究竟是怎么一回事.下面截取范例5-4中导航栏部分的代码: <divdata-role="foote ...
- [转]浅谈Python web框架
说到web framework,Ruby的世界Rails一统江湖,而Python则是一个百花齐放的世界,各种micro-framework.framework不可胜数,不完全列表见:http://wi ...