- 分享
- 0
- 人气
- 0
- 主题
- 4
- 帖子
- 672
- UID
- 122737
- 积分
- 476
- 阅读权限
- 16
- 注册时间
- 2008-2-3
- 最后登录
- 2015-5-11
- 在线时间
- 649 小时
|
计算的部分
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
public class Operation
{
private double _numberA = 0;
private double _numberB = 0;
public double NumberA
{
get { return _numberA; }
set { _numberA = value; }
}
public double NumberB
{
get { return _numberB; }
set { _numberB = value; }
}
public virtual double GetResult()
{
double result = 0;
return result;
}
}
class OperationAdd : Operation
{
public override double GetResult()
{
double result = 0;
result = NumberA + NumberB;
return result;
}
}
class OperationSub : Operation
{
public override double GetResult()
{
double result = 0;
result = NumberA - NumberB;
return result;
}
}
class OperationMul : Operation
{
public override double GetResult()
{
double result = 0;
result = NumberA * NumberB;
return result;
}
}
class OperationDiv : Operation
{
public override double GetResult()
{
double result = 0;
if (NumberB == 0)
{
throw new Exception("Number B cannot be 0");
}
result = NumberA / NumberB;
return result;
}
}
public class OperationFactory
{
public static Operation CreateOperate(string operate)
{
Operation ope = null;
switch (operate)
{
case "+":
ope = new OperationAdd();
break;
case "-":
ope = new OperationSub();
break;
case "*":
ope = new OperationMul();
break;
case "/":
ope = new OperationDiv();
break;
}
return ope;
}
}
}
client 部分
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class watever
{
static void Main(string[] args)
{
try
{
Console.Write("please insert value A");
string NumberA = Console.ReadLine();
Console.Write("please insert a calculation method(+,-,*,/)");
string operate = Console.ReadLine();
Console.Write("please insert value B");
string NumberB = Console.ReadLine();
string result = "";
result = Convert.ToString(Operation.GetResult(Convert.ToDouble(NumberA), Convert.ToDouble(NumberB), operate));
Console.Write("the result is " + result);
Console.ReadLine();
}
catch (Exception ex)
{
Console.Write("invalid insert asdasdasdasddddssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss"+ex.Message);
}
}
}
}
我看了很久看不出哪里错,请各位高手帮忙解围
error message:Error 1 No overload for method 'GetResult' takes '3' arguments C:\Documents and Settings\Kang\Desktop\testing\ConsoleApplication1\ConsoleApplication1\Class2.cs 21 43 ConsoleApplication1
[ 本帖最后由 我是大猪头 于 2009-7-6 06:40 PM 编辑 ] |
|