FxZ,C#开发职位面试测试题(30分钟内必须完成)
1. Refactor the following code (C#) to use polymorphism instead of if-else. Please provide your answer in C#, Java or C++. Alternatively for partial points, you could describe the type of change using UML to aid your response.
public class Calculator
{
public int Calculate(int a, int b, Operation operation)
{
if (operation.Type == "add")
{
return a + b;
}
else if (operation.Type == "subtract")
{
return a - b;
}
else if (operation.Type == "multiply")
{
return a * b;
}
else
{
throw new Exception("Unknown operation type");
}
}
}
public class Operation
{
public string Type { get; set; }
}
My Initial Answer:
publicclassCalculator
{
publicint NumberA { get;set;}
publicint NumberB { get; set; }
publicvirtuallong Calculate(int a, int b);
}
publicclassAddCalculator : Calculator
{
publicint NumberA { get; set; }
publicint NumberB { get; set; }
publicoverridelong Calculate(int a, int b)
{
return NumberA + NumberB;
}
}
publicclassMinusCalculator : Calculator
{
publicint NumberA { get; set; }
publicint NumberB { get; set; }
publicoverridelong Calculate(int a, int b)
{
return NumberA - NumberB;
}
}
publicclassMultiplyCalculator : Calculator
{
publicint NumberA { get; set; }
publicint NumberB { get; set; }
publicoverridelong Calculate(int a, int b)
{
return NumberA * NumberB;
}
}
2. The following two tables contain data relating to stock holdings and stock prices respectively:

How would you manipulate this data in order to return the total value (Units * Price) of the client holdings in each stock (you can use SQL, Excel functions or any other means to answer this)?
My Initial Answer:
Select StockHoldings.Units as x, StockPrice.PrizeNZD as y, sum(x*y) from StockHoldings join StockPrice on StockHoldings.StockCode= StockPrice. StockCode group by StockHoldings.ClientID
3. List as many faults with the following code as you can find
Public Class ClassRubbish
Public Function ReallyRubbishFunction(clientRecords As List)
Dim i, j As Decimal
If clientRecords.Count <= 0 Then
clientRecords.MoveFirst()
Do Until clientRecords.AtEnd()
Console.WriteLine("I've got another clientrecord!")
i = i + 1
''' following line of code commented out by Jason 5/02/2014
'''clientRecords.MoveNext()
Loop
End If
Console.WriteLine("Total number of client records" & 5)
End Function
End Class
4. The following code could be simplified / consolidated. Rewrite it in a more sensible way:
void CalculateTaxAndRewardPoints()
{
if (state == TEXAS)
{
rate = TX_RATE;
amt = baseRate * TX_RATE;
calc = 2 * basis(amt) + extra(amt) * 1.05;
}
else if ((state == OHIO) || (state == MAINE))
{
if (state == OHIO)
rate = OH_RATE;
else
rate = MN_RATE;
amt = baseRate * rate;
calc = 2 * basis(amt) + extra(amt) * 1.05;
if (state == OHIO)
points = 2;
}
else
{
rate = 1;
amt = baseRate;
calc = 2 * basis(amt) + extra(amt) * 1.05;
}
}
5. Write some code in any programming language (please specify which) that accepts an integer variable and returns a string variable containing the word “FIZZ” if the integer is a multiple of 3, “BUZZ” if it is a multiple of 5, “FIZZBUZZ” if it is a multiple of both 3 and 5, or “REJECT” if it is a multiple of neither 3 nor 5.
FxZ,C#开发职位面试测试题(30分钟内必须完成)的更多相关文章
- opencv+opencv_contrib 人脸识别和检测 python开发环境快速搭建(30分钟)图文教程
很多朋友为了学习python.ML(机器学习).DL(深度学习).opencv等花费了大量时间配置安装环境(一个朋友花了4天时间才配置好)各种搜索.下载.安装配置,出问题等. 市面上的配置资料很多,选 ...
- 深入浅出HTTP协议(WEB开发和面试必备)
1. 基础概念篇 a.简介 HTTP是Hyper Text Transfer Protocol(超文本传输协议)的缩写.它的发展是万维网协会(World Wide Web Consortium)和 ...
- 正则表达式30分钟入门教程<转载>
来园子之前写的一篇正则表达式教程,部分翻译自codeproject的The 30 Minute Regex Tutorial. 由于评论里有过长的URL,所以本页排版比较混乱,推荐你到原处查看,看完了 ...
- 30分钟LINQ教程【转】
千万别被这个页面的滚动条吓到!!! 我相信你一定能在30分钟之内看完它!!! 在说LINQ之前必须先说说几个重要的C#语言特性 一:与LINQ有关的语言特性 1.隐式类型 (1)源起 在隐式类型出现之 ...
- 偷窥篇:重要的C#语言特性——30分钟LINQ教程
本文转自:http://www.cnblogs.com/liulun/archive/2013/02/26/2909985.html 千万别被这个页面的滚动条吓到!!! 我相信你一定能在30分钟之内看 ...
- CentOS 30分钟部署 .net core 在线客服系统
前段时间我发表了一系列文章,开始介绍基于 .net core 的在线客服系统开发过程.期间有一些朋友希望能够给出 Linux 环境的安装部署指导,本文基于 CentOS 8.3 来安装部署.在本文中我 ...
- HTML 30分钟入门教程
作者:deerchao 转载请注明来源 本文目标 30分钟内让你明白HTML是什么,并对它有一些基本的了解.一旦入门后,你可以从网上找到更多更详细的资料来继续学习. 什么是HTML HTML是英文Hy ...
- 30分钟连接树莓派到微软云 Azure IoT Hub,并将数据进行可视化
更多内容,关注公众号: 树莓派是很多动手达人必备的小玩具,本节内容,让我们拿出树莓派,在30分钟内,将树莓派连接到微软云Azure的IoT Hub,然后将温湿度曲线可视化.(本节内容完整视频在文章末尾 ...
- Apple Watch程序开发30分钟秒懂
苹果公司Apple Watch智能手表正在备受追捧,迅速掌握Apple Watch的APP架构,环境搭建,及实例开发将会让开发者占尽先机.我赢职场全国首发,30分钟玩转Apple Watch应用开发实 ...
随机推荐
- 使用Web页面配置ESP8266的参数
前言 使用Web页面配置ESP8266的参数相对于使用串口AT指令配置更加直观和简单.与配置路由器方式类似. 基本思路 基本思路是ESP8266工作AP模式下,作为TCP Server监听TCP Cl ...
- (转)基于 Token 的身份验证
原文:https://ninghao.net/blog/2834 最近了解下基于 Token 的身份验证,跟大伙分享下.很多大型网站也都在用,比如 Facebook,Twitter,Google+,G ...
- JavaScript一个简易枚举类型实现扑克牌
<script type="text/javascript"> /** * 这个函数创建一个新的枚举类型,实参对象表示类的每个实例的名字和值 * 返回值是一个构造函数, ...
- [TYVJ1728/BZOJ3224]普通平衡树-替罪羊树
Problem 普通平衡树 Solution 本题是裸的二叉平衡树.有很多种方法可以实现.这里打的是替罪羊树模板. 此题极其恶心. 前驱后继模块需要利用到rank模块来换一种思路求. 很多细节的地方容 ...
- 【SqlServer系列】子查询
1 概述 1.1 已发布[SqlServer系列]文章 [SqlServer系列]SQLSERVER安装教程 [SqlServer系列]数据库三大范式 [SqlServer系列]表单查询 [Sq ...
- Python如何实现单步调试
遇到大型python项目,如何定位问题和监控程序的运行状态是一个程序员必须掌握的技能,今天小编为你带来python程序的单步调试方法,方便易用,简单易记! 首先你需要在所调试程序的开头中:import ...
- java封装性、继承性及关键字
方法的参数传递(重点.难点)1.形参:方法声明时,方法小括号内的参数 实参:调用方法时,实际传入的参数的值 2.规则:java中的参数传递机制:值传递机制 1)形参是基本数据类型的:将实参的值传递 ...
- C/C++中static关键字的用法
1.什么是static? static 是C/C++中很常用的修饰符,它被用来控制变量的存储方式和可见性. 1.1static的引入 我们知道在函数内部定义的变量,当程序执行到它的定义处时,编译器为它 ...
- VerilogHDL概述与数字IC设计流程学习笔记
一.HDL的概念和特征 HDL,Hard Discrimination Language的缩写,翻译过来就是硬件描述语言.那么什么是硬件描述语言呢?为什么不叫硬件设计语言呢?硬件描述语言,顾名思义就是 ...
- 将bbr功能合入到centos7.3
今天将bbr的算法合入到了centos7.3的内核,基线内核版本是3.10.0-514.el7.x86_64, 内核编译测试通过.感谢隆春和文洋的帮助,隆春是将bbr合入到了cgslv5版本. 这种反 ...