2014-05-11 05:29

题目链接

原题:

  1. Design remote controller for me.

题目:设计一个遥控器。

解法:遥控什么?什么遥控?传统的红外线信号吗?我只能随便说说思路吧。不知道这算什么类型的面试题,真遇到的话也算是倒了霉了。想了半天恍然大悟:原来是考察设计模式。查了相关资料后发现命令模式比较符合题意,所以就依葫芦画瓢写了个例子。

代码:

  1. // http://www.careercup.com/question?id=6366101810184192
  2. interface ICommand {
  3. public abstract void execute();
  4. }
  5.  
  6. public class PowerOnCommand implements ICommand {
  7. @Override
  8. public void execute() {
  9. // TODO Auto-generated method stub
  10. System.out.println("Power on.");
  11. }
  12.  
  13. }
  14.  
  15. public class PowerOffCommand implements ICommand {
  16. @Override
  17. public void execute() {
  18. // TODO Auto-generated method stub
  19. System.out.println("Power off.");
  20. }
  21. }
  22.  
  23. import java.util.Vector;
  24.  
  25. public class RemoteController {
  26. private Vector<ICommand> buttons;
  27. private String[] configuration = {"PowerOnCommand", "PowerOffCommand"};
  28.  
  29. public RemoteController() {
  30. // TODO Auto-generated constructor stub
  31. buttons = new Vector<ICommand>();
  32. for (String commandType : configuration) {
  33. try {
  34. try {
  35. buttons.add((ICommand) Class.forName(commandType).newInstance());
  36. } catch (InstantiationException e) {
  37. // TODO Auto-generated catch block
  38. e.printStackTrace();
  39. } catch (IllegalAccessException e) {
  40. // TODO Auto-generated catch block
  41. e.printStackTrace();
  42. }
  43. } catch (ClassNotFoundException e) {
  44. // TODO Auto-generated catch block
  45. e.printStackTrace();
  46. }
  47. }
  48. }
  49.  
  50. public void push(int commandIndex) {
  51. try {
  52. buttons.elementAt(commandIndex).execute();
  53. } catch (ArrayIndexOutOfBoundsException e) {
  54. // TODO: handle exception
  55. }
  56. }
  57. }

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. 音乐社交APP源码 V1.1

    1.关于音乐曲库,对接的是百度音乐,会自动随搜索链接百度曲库2.便捷聊天,采用xmpp基本架构.3.加入和整理了群聊天.4.分布式聊天,喜欢该专辑直接进入聊天,喜欢该音乐的进入聊天.5.采用兴趣社交和 ...

  2. SMTP sendMail 失败解决办法

    If you are seeing messages like this in your message log when running a process through the process ...

  3. [原创] 初识Agile/CMMI/Scrum

    一.背景介绍 在朋友(aehyok)的建议下,初步去了解Visual Studio Online,简称VS Online(即原来的 Team Foundation Service,简称TFS) VS ...

  4. C#中补0

     C#中补0 编写人:CC阿爸 2014-3-16 首先先增加两个左补齐又补齐的函数 #region 该函数动态添加空格,对齐小票 public string AddSpace(string text ...

  5. [Redis] RDB & AOF

    http://my.oschina.net/davehe/blog/174662 rdb - 存在dump.rdb 的二进制文件中 dump 整个db, 数据多的时候,不合适频繁保存,保存的时间间隔应 ...

  6. HBase分布式安装

    安装HBase之前需要先安装Hadoop,因为HBase是运行在Hadoop集群上的.安装Hadoop可以参照http://www.cnblogs.com/stGeekpower/p/3307289. ...

  7. 【转】Spark性能测试报告

    RDD可以很好地适用于支持数据并行的批量分析应用,包括数据挖掘,机器学习,图算法等,因为这些程序通常都会在很多记录上执行相同的操作.RDD不太适合那些异步更新共享状态的应用,例如并行web爬行器.因此 ...

  8. Laravel 5 基础(十一)- Eloquent 关系

    一个用户可能有多个文章,一个文章是某个用户书写的,这就是关系.同样文章中可能包含多个 TAG,而一个 TAG 可能关联多个文章. 在项目中,我们已经有了 User.php,也就是用户模型,查看一下,相 ...

  9. 【原创】小白学jquery Mobile《构建跨平台APP:jQuery Mobile移动应用实战》连载五(给按钮加图标)

    在范例5-4所使用的导航栏中,已经为按钮加入了图标的样式,但是当时并没有介绍按钮的图标究竟是怎么一回事.下面截取范例5-4中导航栏部分的代码: <divdata-role="foote ...

  10. [转]浅谈Python web框架

    说到web framework,Ruby的世界Rails一统江湖,而Python则是一个百花齐放的世界,各种micro-framework.framework不可胜数,不完全列表见:http://wi ...