码迷,mamicode.com
首页 > 其他好文 > 详细

Calculation控制台

时间:2015-11-18 19:40:57      阅读:127      评论:0      收藏:0      [点我收藏+]

标签:

接口

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace susuusu
{
    interface Interface1
    {
        int calculate(int a, int b,int c);
    }
}

 加法类

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace susuusu
{
    class Add:Interface1
    {
        public int calculate(int a, int b,int c)
        {
            return a + b + c;
        }
    }
}

 减法类

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace susuusu
{
    class Subtract:Interface1
    {
       public int calculate(int a, int b, int c)
        {
            return a - b - c;
        }
    }
}

 乘法类

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace susuusu
{
    class Multiply:Interface1
    {
       public int calculate(int a, int b, int c)
        {
            return a * b * c;
        }
    }
}

 除法类

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace susuusu
{
    class Except:Interface1
    {
       public int calculate(int a, int b, int c)
        {
            return a / b / c;
        }
    }
}

 环境角色

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace susuusu
{
    class Environment
    {
        private Interface1 inter;
        public Environment(Interface1 face)
        {
            inter = face;
        }
        public Interface1 gewrt()
        {
            return inter;
        }
        public void setwrt(Interface1 face)
        {
            inter = face;
        }
        public int calculate(int a, int b,int c)
        {
            return inter.calculate(a, b,c);
        }
    }
}

 Main方法

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace susuusu
{
    class Program
    {
        static void Main(string[] args)
        {
            Add addss = new Add();
            Environment environment = new Environment(addss);
           Console.WriteLine( environment.calculate(4, 5,7));
           Subtract subtrss = new Subtract();
           Environment environment1 = new Environment(subtrss);
           Console.WriteLine(environment1.calculate(911, 81, 2));
           Multiply mulit = new Multiply();
           Environment environment2 = new Environment(mulit);
           Console.WriteLine(environment2.calculate(12, 45, 12));
           Except except1 = new Except();
           Environment environment3 = new Environment(except1);
           Console.WriteLine(environment3.calculate(81, 9, 9));
           Console.ReadLine();
        }
    }
}

 总结

总的感觉来书还是控制台比较好写一些!在不同的环境下写相同的程序,感受一下不同!

 

Calculation控制台

标签:

原文地址:http://www.cnblogs.com/lizanqirxx/p/4975600.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!