zoukankan      html  css  js  c++  java
  • 封装,策略,Asp换脸

    封装、策略

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace 算
    {
        public interface Isuan
        {
             int calculate(int a, int b);
        }
        public  class add : Isuan
        {
            public int calculate(int a,int b) 
            {
                return a + b;
            }
        }
        public class sub : Isuan 
        {
            public int calculate(int a, int b)
            {
                return a - b;
            }
        }
        public class mal : Isuan 
        {
            public int calculate(int a, int b) 
            {
                return a * b;
            }
        }
        public class div : Isuan 
        {
            public int calculate(int a, int b)
            {
                return a / b;
            }
        }
    }
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.IO;
    
    namespace 算
    {
        class fuhao
        {
            private Isuan fh;
            public fuhao(string a)
            {
                switch(a)
                {
                    case"+":
                        fh = new add();
                        break;
                    case "-":
                        fh = new sub();
                        break;
                    case "*":
                        fh = new mal();
                        break;
                    case "/":
                        fh = new div();
                        break;
                }
            }
            public int jisuan(int a, int b) 
            {
                return fh.calculate(a, b);
            }
    
        }
    }
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using System.IO;
    
    namespace 算
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
            private int An;
            private void button2_Click(object sender, EventArgs e)
            {
                this.Close();
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
    fuhao clacuter = new fuhao(comboBox1.Text);
                An = clacuter.jisuan(int.Parse(textBox1.Text), int.Parse(textBox2.Text));
    if (textBox3.Text == An.ToString()) { MessageBox.Show("回答正确!"); } else { MessageBox.Show("回答错误!"); } textBox1.Clear(); textBox2.Clear(); comboBox1.Text = ""; textBox3.Clear(); } private void textBox3_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { fuhao clacuter = new fuhao(comboBox1.Text);  An = clacuter.jisuan(int.Parse(textBox1.Text), int.Parse(textBox2.Text)); if (textBox3.Text == An.ToString()) { MessageBox.Show("回答正确!"); } else { MessageBox.Show("回答错误!"); } textBox1.Clear(); textBox2.Clear(); comboBox1.Text = ""; textBox3.Clear(); } } } }


    asp换脸

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    
    /// <summary>
    ///fuhao 的摘要说明
    /// </summary>
    public class fuhao
    {
        private Isuan s;
        public fuhao(string a)
        {
            switch (a)
            {
                case"+":
                    s = new add();
                    break;
                case "-":
                    s = new sub();
                    break;
                case "*":
                    s = new cml();
                    break;
                case "/":
                    s = new div();
                    break;
            }
        }
        public int suan(int a, int b) 
        {
            return s.cla(a,b);
        }
      
    }
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    
    /// <summary>
    ///suan 的摘要说明
    /// </summary>
    
    
         public interface Isuan 
        {
             int cla(int a, int b);
        }
        public class add:Isuan
        {
            public int cla(int a, int b) 
            {
                return a + b;
            }
        }
        public class sub:Isuan
        {
            public int cla(int a, int b)
            {
                return a - b;
            }
        }
        public class cml:Isuan
        {
            public int cla(int a, int b)
            {
                return a * b;
            }
        }
        public class div:Isuan
        {
            public int cla(int a, int b)
            {
                return a / b;
            }
        }
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    
    public partial class _Default : System.Web.UI.Page
    {
        private int An;
        protected void Page_Load(object sender, EventArgs e)
        {
    
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            fuhao b = new fuhao(TextBox2.Text);
            An=b.suan(int.Parse(TextBox1.Text),int.Parse(TextBox3.Text));
            if (TextBox4.Text == An.ToString())
            {
                Response.Write("回答正确!");
            }
            else 
            {
                Response.Write("回答错误!");
            }
        }
    }

  • 相关阅读:
    SpringMVC源码分析--HandlerMappings
    你真的懂wait、notify和notifyAll吗
    深入理解DefaultMessageListenerContainer
    起步
    ZOJ 3827 Information Entropy (2014牡丹江区域赛)
    Spring简化配置
    对于一个IE8兼容性问题的反思
    xcode7.1.1不能真机调试ios9.2系统设备的解决方法
    CSS3怎样实现超出指定文本以省略号显示效果
    网易2016年研发project师编程题(2)
  • 原文地址:https://www.cnblogs.com/fanxiaotian/p/5002667.html
Copyright © 2011-2022 走看看