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("回答错误!");
            }
        }
    }

  • 相关阅读:
    mysql数据库常用指令
    解决windows的mysql无法启动 服务没有报告任何错误的经验。
    “Can't open file for writing”或“operation not permitted”的解决办法
    启动Apache出现错误Port 80 in use by "Unable to open process" with PID 4!
    如何打开windows的服务services.msc
    常见的HTTP状态码 404 500 301 200
    linux系统常用的重启、关机指令
    (wifi)wifi移植之命令行调试driver和supplicant
    linux(debian)安装USB无线网卡(tp-link TL-WN725N rtl8188eu )
    alloc_chrdev_region申请一个动态主设备号,并申请一系列次设备号
  • 原文地址:https://www.cnblogs.com/fanxiaotian/p/5002667.html
Copyright © 2011-2022 走看看