using System
using System.Collections.Generic
using System.Linq
using System.Text
namespace SimpleFictory
{
public abstract class OperationBase
{
private double _num = 0
private double _number = 0
public double Num
{
get { return _num}
set { _num = value}
}
public double Number
{
get { return _number}
set { _number = value}
}
public abstract double Amount()
}
class Add : OperationBase
{
public override double Amount()
{
double result = 0
result = Num + Number
return result
}
}
class Sub : OperationBase
{
public override double Amount()
{
double result = 0
result = Num - Number
return result
}
}
class Minus : OperationBase
{
public override double Amount()
{
double result = 0
result = Num * Number
return result
}
}
class Div : OperationBase
{
public override double Amount()
{
double result = 0
if (Number == 0)
throw new Exception("除数不能为0。")
result = Num / Number
return result
}
}
public abstract class OperationFactory
{
public static OperationBase createOperate(string operate)
{
OperationBase oper = null
switch (operate)
{
case "+":
oper = new Add()
break
case "-":
oper = new Sub()
break
case "*":
oper = new Minus()
break
case "/":
oper = new Div()
break
}
return oper
}
}
class Program
{
static void Main(string[] args)
{
OperationBase oper
oper = OperationFactory.createOperate("+")//可根据要求更改运算符,仅以加法为例。
oper.Num = 1
oper.Number = 2
double result = oper.Amount()
Console.WriteLine("结果是{0}", result)
Console.ReadKey()
}
}
}
qq小程序soso交友更改性别:1、先在qq小程序里面,找到soso,点击打开程序。
2、进入到soso后,点击右下角的我的。
3、在我的界面,能看到右上角的编辑资料选项,点击打开。
4、然后能看到我的性别修改选项,选择性别。
5、重新选择完成后,滑动屏幕到底部,点击保存。
6、保存成功后,返回到我的界面,能看到性别已经修改成功。
public class Example{public static void main(String[] args){
Scanner input=new Scanner(System.in)
//显示菜单
System.out.println("请选择性别:1-男 2-女")
try{
int sex=input.nextInt()
if(sex==1){
System.out.println("您选择了男!")
}else if(sex==2){
System.out.println("您选择了女!")
}else{
System.out.println("只能选择1和2!")
}
}catch(Exception e){
System.out.println("菜单选择有误,只能输入数字:"+e.getMessage())
}
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)