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的更多相关文章

  1. Careercup - Microsoft面试题 - 6366101810184192

    2014-05-10 22:30 题目链接 原题: Design database locks to allow r/w concurrency and data consistency. 题目:设计 ...

  2. Careercup - Microsoft面试题 - 24308662

    2014-05-12 07:31 题目链接 原题: I have heard this question many times in microsoft interviews. Given two a ...

  3. Careercup - Microsoft面试题 - 5700293077499904

    2014-05-12 00:02 题目链接 原题: For a given map (ie Bing map) given longitude/latitude/ how would you desi ...

  4. Careercup - Microsoft面试题 - 5204967652589568

    2014-05-11 23:57 题目链接 原题: identical balls. one ball measurements ........ dead easy. 题目:9个看起来一样的球,其中 ...

  5. Careercup - Microsoft面试题 - 5175246478901248

    2014-05-11 23:52 题目链接 原题: design an alarm clock for a deaf person. 题目:为聋人设计闹钟? 解法:聋人听不见,那么闪光.震动都可行.睡 ...

  6. Careercup - Microsoft面试题 - 5718181884723200

    2014-05-11 05:55 题目链接 原题: difference between thread and process. 题目:请描述进程和线程的区别. 解法:操作系统理论题.标准答案在恐龙书 ...

  7. Careercup - Microsoft面试题 - 5173689888800768

    2014-05-11 05:21 题目链接 原题: Complexity of a function: int func_fibonacci ( int n) { ) { return n; } el ...

  8. Careercup - Microsoft面试题 - 6282862240202752

    2014-05-11 03:56 题目链接 原题: Given an integer array. Perform circular right shift by n. Give the best s ...

  9. Careercup - Microsoft面试题 - 5428361417457664

    2014-05-11 03:37 题目链接 原题: You have three jars filled with candies. One jar is filled with banana can ...

随机推荐

  1. 《你是我的小羊驼》游戏ios源码

    <ignore_js_op> <ignore_js_op> <ignore_js_op> <ignore_js_op>源码下载:http://code. ...

  2. js 实现获取对象所有键名(key)的方法

    1.for in 循环 并且使用hasOwnProperty 方法 var jsonObject1 = { "name": "xiaoming", " ...

  3. Django搭建及源码分析(三)---+uWSGI+nginx

    每个框架或者应用都是为了解决某些问题才出现旦生的,没有一个事物是可以解决所有问题的.如果觉得某个框架或者应用使用很不方便,那么很有可能就是你没有将其使用到正确的地方,没有按开发者的设计初衷来使用它,当 ...

  4. Oracle中rownum的用法

    rownum是Oracle对查询结果进行顺序编号,第一行分配1,第二行2,以此类推.rownum不能以任何表的名称作为前缀. rownum这个伪字段可以用于控制返回的记录行数. 例如表:student ...

  5. MongoDB(1):常用操作命令大全

    MongoDB常用操作命令大全(转) http://www.jb51.net/article/48217.htm 成功启动MongoDB后,再打开一个命令行窗口输入mongo,就可以进行数据库的一些操 ...

  6. 当数据0跟if判断冲突的时候

    我是很无奈的,以后都要2,3,4,5这样去标志状态: 分配状态:<select name="is_send" > <option selected="s ...

  7. 学习jQuery在表单信息修改之中的常用方法;

    submitHandler: function (form) { var parm = $("#myform").serialize(); var url = $("#m ...

  8. asp.net导出excel示例代码

    asp.net导出excel的简单方法. excel的操作,最常用的就是导出和导入. 本例使用NPOI实现. 代码:/// <summary> );             ;       ...

  9. ajax 注意点

    1. 为了把数据发送到服务器,应该使用POST 方法,为了从服务器检索数据,应该使用GET 方法. 2.ajax 完整参数, url  发送的地址 http://localhost/default.a ...

  10. 最大子列和CT 01-复杂度2 Maximum Subsequence Sum

    Given a sequence of K integers { N​1​​, N​2​​, ..., N​K​​ }. A continuous subsequence is defined to ...