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 ...
 
随机推荐
- PUTTY使用Ctrl+s僵死的问题
			
算是分享个小经验吧! 一直都是使用VM+PUTTY的方式调试Linux程序,有时候在Vi中编辑了程序,Windowns下旧习难改,顺手就Ctrl+s了,尽管我知道Vi的保存是:w. 很不幸这时的PUT ...
 - .NET如何从配置文件中获取连接字符串
			
一.设置配置文件 <configuration> <!--在configuration下创建一个connectionStrings--> <connectionStrin ...
 - ElasticSearch-PHP的API使用(二)
			
1:索引内的一个文档的创建(相当表记录的添加) 比如:要添加一条记录 INSERT INTO blog(title,content,add_time) VALUES('ElasticSearch-PH ...
 - [视频]物联网应用-ARM mbed-来至MultiTech Systems的解决方案
			
ARM公司面向物联网及可穿戴市场,近期可谓是动作频频,先是发布了专为物联网及可穿戴领域而生的Cortex-M7架构,接着又发布了mbed物联网操作系统.意图在物联网领域构筑一套坚不可摧的生态系统. 这 ...
 - protobuf的使用
			
Protobuf的安装 正确安装方法: [http://blog.csdn.net/guoyilongedu/article/details/17093811] linux下安装protobuf教程+ ...
 - 【PHP】金额数字转换成大写形式
			
<?php /*将数字金额转成大写*/ function num_to_upper($num) { $d = array('零','壹','贰','叁','肆','伍','陆','柒','捌', ...
 - 仿淘宝颜色属性选择展示代码(jQuery)
			
模仿淘宝商品选择颜色和尺寸的效果,即选择商品颜色和尺寸的时候,把选择的颜色和尺寸放到一个页面容器里面,不足之处,还望指教. <!DOCTYPE HTML> <html lang=&q ...
 - redis 入门
			
1.命令行工具 在windows上巧命令行指令,实在是令人痛苦,本人实在是受不了windows下cmd的笨,powershell的蠢,只能换一个了. 介绍一款cmd工具cmder(github上开源) ...
 - PHP实习生面经--两天四面
			
这两天一共面了四家公司,之前投了很多还在想怎么没有叫面试的,后来接连来了四个.下面一个一个做个总结. 1.创想空间(www.quanshi.com) 在五环边上的软件园里,占了一个楼的大概一层吧,算是 ...
 - 关于 mvc 中 连字符 - 和下划线 _转换的问题。
			
[潜水]大崔||哈尔滨(759666247) 10:02:16 如图 C#不承认 “-”[知府]古道今-湖北\xig<systemobject@126.com> 10:03:54 ...