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分钟内必须完成)的更多相关文章

  1. opencv+opencv_contrib 人脸识别和检测 python开发环境快速搭建(30分钟)图文教程

    很多朋友为了学习python.ML(机器学习).DL(深度学习).opencv等花费了大量时间配置安装环境(一个朋友花了4天时间才配置好)各种搜索.下载.安装配置,出问题等. 市面上的配置资料很多,选 ...

  2. 深入浅出HTTP协议(WEB开发和面试必备)

    1. 基础概念篇   a.简介 HTTP是Hyper Text Transfer Protocol(超文本传输协议)的缩写.它的发展是万维网协会(World Wide Web Consortium)和 ...

  3. 正则表达式30分钟入门教程<转载>

    来园子之前写的一篇正则表达式教程,部分翻译自codeproject的The 30 Minute Regex Tutorial. 由于评论里有过长的URL,所以本页排版比较混乱,推荐你到原处查看,看完了 ...

  4. 30分钟LINQ教程【转】

    千万别被这个页面的滚动条吓到!!! 我相信你一定能在30分钟之内看完它!!! 在说LINQ之前必须先说说几个重要的C#语言特性 一:与LINQ有关的语言特性 1.隐式类型 (1)源起 在隐式类型出现之 ...

  5. 偷窥篇:重要的C#语言特性——30分钟LINQ教程

    本文转自:http://www.cnblogs.com/liulun/archive/2013/02/26/2909985.html 千万别被这个页面的滚动条吓到!!! 我相信你一定能在30分钟之内看 ...

  6. CentOS 30分钟部署 .net core 在线客服系统

    前段时间我发表了一系列文章,开始介绍基于 .net core 的在线客服系统开发过程.期间有一些朋友希望能够给出 Linux 环境的安装部署指导,本文基于 CentOS 8.3 来安装部署.在本文中我 ...

  7. HTML 30分钟入门教程

    作者:deerchao 转载请注明来源 本文目标 30分钟内让你明白HTML是什么,并对它有一些基本的了解.一旦入门后,你可以从网上找到更多更详细的资料来继续学习. 什么是HTML HTML是英文Hy ...

  8. 30分钟连接树莓派到微软云 Azure IoT Hub,并将数据进行可视化

    更多内容,关注公众号: 树莓派是很多动手达人必备的小玩具,本节内容,让我们拿出树莓派,在30分钟内,将树莓派连接到微软云Azure的IoT Hub,然后将温湿度曲线可视化.(本节内容完整视频在文章末尾 ...

  9. Apple Watch程序开发30分钟秒懂

    苹果公司Apple Watch智能手表正在备受追捧,迅速掌握Apple Watch的APP架构,环境搭建,及实例开发将会让开发者占尽先机.我赢职场全国首发,30分钟玩转Apple Watch应用开发实 ...

随机推荐

  1. linux实训

    目  录 Unit 1 操作系统安装.... 3 1.1 多操作系统安装... 3 1.1.1 VMware简介... 3 1.1.2 VMWare基本使用... 4 1.2 安装Red Hat Li ...

  2. Command "python setup.py egg_info" failed with error code 10

    1:今天系统重装以后,下载了新的版本的python3.6.1.然后想通过pycurl模块测试URL,突然发现windows10下我无法通过pip安装pycurl模块了,报错内容如下 Collectin ...

  3. 0001.如何在Windows7(x64)上安装 Sharepoint2010 Fundation

    一.修改Config.xml文件 到目录:"C:\Program Files (x86)\MSECache\SharePoint2010\Files\Setup"下去修改confi ...

  4. JavaScript 之 HelloWorld编写

    HelloWorld.html 代码如下: <html><body><script type="text/javascript">documen ...

  5. Android - 传统蓝牙(蓝牙2.0)

    Android Bluetooth 源码基于 Android L [TOC] Reference BluetoothAdapter 首先调用静态方法getDefaultAdapter()获取蓝牙适配器 ...

  6. Jenkins: 执行 PowerShell 命令

    Jenkins 默认是不支持执行 PowerShell 命令的,需要安装插件才能完成这样的任务.本文将介绍 Jenkins PoserShell 插件的基本用法和常见问题. 安装 PowerShell ...

  7. Json 工具介绍 fastjson gson jackson

    1. fastjson fastjson是一个Java语言编写的高性能功能完善的JSON库.它采用一种“假定有序快速匹配”的算法,把JSON Parse的性能提升到极致, 是目前Java语言中最快的J ...

  8. 到底什么样的企业才适合实施SAP系统?

    SAP系统作为全宇宙第一的ERP,号称世界500强里面有80%的企业部署了SAP系统,总部位于德国沃尔多夫市,在全球拥有6万多名员工,遍布全球130个国家,并拥有覆盖全球11,500家企业的合作伙伴网 ...

  9. react - 解刨组件的多种写法

    一,原始的createClass写法 对于写react组件,很多人第一印象往往是createClass,这是因为createClass是react组件最原始的写法,基本每个学react的人都是接触这种 ...

  10. C语言_第一讲_C语言入门

    一.C语言的简介 1.C语言是一个标准,而执行标准的时候产生的自动化程序则是编译器2.了解:1983年美国国家标准化歇会(ANSI)制定了C语言标准.C语言的特点:3.代码的可移植性(理想状态是代码可 ...