首页 技术 正文
技术 2022年11月17日
0 收藏 368 点赞 4,542 浏览 2955 个字

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:

FxZ,C#开发职位面试测试题(30分钟内必须完成)

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.

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,497
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,910
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,744
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,498
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,136
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,300