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. Java代码优化六大原则

    单一职责 代码优化第一步,单一职责原则 (Single Responsibility Principle).对于一个Java类,应该仅有一个引起它变化的原因,也就是说,一个类中,应该是一组相关性很高的 ...

  2. Linux查看内存占用情况

    输入:top PID 进程的ID USER 进程所有者 PR 进程的优先级别,越小越优先被执行 Ninice 值 VIRT 进程占用的虚拟内存 RES 进程占用的物理内存 SHR 进程使用的共享内存 ...

  3. jvm007 jvm知识点总览

    转载来自:http://www.ityouknow.com/ 在江湖中要练就绝世武功必须内外兼备,精妙的招式和深厚的内功,武功的基础是内功.对于武功低(就像江南七怪)的人,招式更重要,因为他们不能靠内 ...

  4. 在ASP.NET MVC中利用Aspose.cells 将查询出的数据导出为excel,并在浏览器中下载。

    正题前的唠叨 本人是才出来工作不久的小白菜一颗,技术很一般,总是会有遇到一些很简单的问题却不知道怎么做,这些问题可能是之前解决过的.发现这个问题,想着提升一下自己的技术水平,将一些学的新的'好'东西记 ...

  5. cocos2dx之WebView踩过的坑(android返回键处理问题)

    最近游戏接入了一个私服平台,由于没有sdk,所以支付相关的操作需要在网页端进行,也就是说点击充值需要在游戏内部弹出一个网页,并定位到平台充值的地址.查阅相关资料后决定使用cocos2dx自带的WebV ...

  6. linux下使用scp远程传输自动输入密码

    由于需要将A服务器的文件 远程传输到B服务器 但是scp命令每次都要手动输入密码 这样脚本执行太繁琐,所以讲A服务器和B服务器互信即可,具体操作如下: 首先在A服务器配置: mkdir -p ~/.s ...

  7. 8.Spark SQL

    Spark SQL 1 Why Apache Spark 2 关于Apache Spark 3 如何安装Apache Spark 4 Apache Spark的工作原理 5 spark弹性分布式数据集 ...

  8. 初学Python(三)——字典

    初学Python(三)——字典 初学Python,主要整理一些学习到的知识点,这次是字典. #-*- coding:utf-8 -*- d = {1:"name",2:" ...

  9. 使用HTML5 FormData对象实现大文件分块上传(断点上传)功能

    FormData是HTML5新增的一个对象,通过FormData对象可以组装一组用 XMLHttpRequest发送请求的键/值对.它可以更灵活方便的发送表单数据,因为可以独立于表单使用.如果你把表单 ...

  10. html5图片上传时IOS和Android均显示摄像头拍照和图片选择

    最近在做信开发时,发现<input type="file" />在IOS中可以拍照或从照片图库选择,而Android系统则显示资源管理器,无拍照选项,网上查找资料,改为 ...