zoukankan      html  css  js  c++  java
  • 封装,策略模式

     1 using System;
     2 using System.Collections.Generic;
     3 using System.Linq;
     4 using System.Text;
     5 using System.IO;
     6 
     7 namespace 出题
     8 {
     9     class Writeclear   //Writeclear类
    10     {
    11        private string a;
    12        private string b;
    13        private string opertaors;
    14        public Writeclear(string A,string B,string Operators)
    15        {
    16            a = A;
    17            b = B;
    18            opertaors = Operators;
    19  
    20        }
    21        
    22        private string x;
    23        private string y;
    24        private string operator1;
    25        public string X
    26        {
    27            set
    28            {
    29                x = value;
    30            }
    31        }
    32        public string Y
    33        {
    34            set
    35            {
    36                y = value;
    37            }
    38        }
    39        public string Operator1
    40        {
    41            set
    42            {
    43                operator1 = value;
    44            }
    45        }
    46   
    47        public void write()
    48        {
    49            StreamWriter a1 = new StreamWriter(a, true);
    50            a1.WriteLine(x);
    51            a1.Close();
    52            StreamWriter a2 = new StreamWriter(b, true);
    53            a2.WriteLine(y);
    54            a2.Close();
    55            StreamWriter a3 = new StreamWriter(opertaors, true);
    56            a3.WriteLine(operator1);
    57            a3.Close();
    58            
    59        }
    60        public void clear()
    61        {
    62            StreamWriter b1 = new StreamWriter(a);
    63            b1.WriteLine("");
    64            b1.Close();
    65            StreamWriter b2 = new StreamWriter(b);
    66            b2.WriteLine("");
    67            b2.Close();
    68            StreamWriter b3 = new StreamWriter(opertaors);
    69            b3.WriteLine("");
    70            b3.Close();
    71        }
    72        
    73 
    74     }
    75 }
     1 using System;
     2 using System.Collections.Generic;
     3 using System.Linq;
     4 using System.Text;
     5 
     6 namespace 出题
     7 {
     8     class calcuall
     9     {
    10         Calculator calculator = new Calculator();
    11         private string opreator2;
    12         public string Operator2
    13         {
    14             set
    15             {
    16                 opreator2 = value;
    17             }
    18         
    19         }
    20         public void cal()
    21         {
    22             if (opreator2 == "+")
    23             {
    24                 calculator.Add();
    25             }
    26             if (opreator2 == "-")
    27             {
    28                 calculator.sub();
    29             }
    30             if (opreator2 == "/")
    31             {
    32                 calculator.division();
    33             }
    34             if (opreator2 == "*")
    35             {
    36                 calculator.multiplication();
    37             }
    38          
    39         }
    40             
    41     
    42     }
    43 }
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace 出题
    {
        class Calculator
        {
            private int z;
            private int x;
            private int y;
            private string operator1;
            private int answer;
            public int X
            {
               
                set
                {
                    x = value;
                }
            }
            public int Y
            {
                set
                {
                    y = value;
                }
            }
            public string Operator1
            {
                set
                {
                    operator1 = value;
                }
            }
            public int Answer
            {
                get
                {
                    return answer;
                }
            }
            public void Add()
            {
                answer= x + y;
     
            }
            public void sub()
            {
                if (x > y)
                {
    
                    answer = x - y;
                }
                else
                {
                    z = y;
                    y = x;
                    x = z;
                    answer = x - y;
                }
                   
            }
            public void multiplication()
            {
                answer = x * y;
            }
            public void division()
            {
                if (y == 0)
                {
                    z = y;
                    y = x;
                    x = z;
                    answer = x / y;
                }
                else
                {
                    answer = x / y;
                }
            }
    
        }
    }

    from1

     1 using System;
     2 using System.Collections.Generic;
     3 using System.ComponentModel;
     4 using System.Data;
     5 using System.Drawing;
     6 using System.Linq;
     7 using System.Text;
     8 using System.Windows.Forms;
     9 using System.IO;
    10 
    11 
    12 namespace 出题
    13 {
    14     public partial class Form1 : Form
    15     {
    16         public Form1()
    17         {
    18             InitializeComponent();
    19         }
    20 
    21 
    22         private void button1_Click(object sender, EventArgs e)
    23         {
    24             string fnm = @"one";
    25             string fnmm = @"tow";
    26             string fnmn = @"fuhao";
    27             Writeclear write1 = new Writeclear(fnm,fnmm,fnmn);
    28             write1.X = textBox1.Text;
    29             write1.Y = textBox2.Text;
    30             write1.Operator1 = comboBox1.Text;
    31             write1.write();
    32             textBox1.Clear();
    33             textBox2.Clear(); 
    34 
    35         }
    36 
    37         private void button2_Click(object sender, EventArgs e)
    38         {
    39             Form2 fam = new Form2();
    40             fam.ShowDialog();
    41          
    42         }
    43 
    44         private void button3_Click(object sender, EventArgs e)
    45         {
    46 
    47             string fnm = @"one";
    48             string fnmm = @"tow";
    49             string fnmn = @"fuhao";         
    50             Writeclear write1 = new Writeclear(fnm, fnmm, fnmn); 
    51             write1.clear();
    52         }
    53       
    54  
    55         }
    56     }

    from2

    sing 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 Form2 : Form
        {
            public Form2()
            {
                InitializeComponent();
            }
    
            int i=1;
           public static int count = -1;
           public static int right = 0;
            private void timer1_Tick(object sender, EventArgs e)
            {
                try
                {
                    int t = int.Parse(textBox5.Text);
                    if (t <= 0)
                    {
                        timer1.Enabled = false;
                        textBox5.Enabled = false;
                        MessageBox.Show("时间到了!");
                        Form3 fr3 = new Form3();
                        fr3.ShowDialog();
    
                    }
                    t = t - 1;
                    textBox5.Text = t.ToString();
    
                }
                catch
                {
     
                }
    
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
                try
                {
                    string t = textBox5.Text;
                    textBox5.Text = t;
                    timer1.Enabled = true;
                    timer1.Interval = 1000;
                    timer1.Start();
                }
                catch
                { 
    
                }
                baaa();
                count++;
            
    
            }
    
            private void textBox4_KeyDown(object sender, KeyEventArgs e)
            { 
                Calculator calculator=new Calculator();
                calcuall cal=new calcuall();
                calculator.X=int.Parse(textBox1.Text);
                calculator.Y=int.Parse(textBox3.Text);
                calculator.Operator1=textBox2.Text;
                cal.Operator2=textBox2.Text;                     
                if (e.KeyCode == Keys.Enter)
                {
                    if (textBox4.Text ==calculator.Answer.ToString() )
                    {
                        MessageBox.Show("回答正确!");
                        right++;

    from3

     1 using System;
     2 using System.Collections.Generic;
     3 using System.ComponentModel;
     4 using System.Data;
     5 using System.Drawing;
     6 using System.Linq;
     7 using System.Text;
     8 using System.Windows.Forms;
     9 
    10 namespace 出题
    11 {
    12     public partial class Form3 : Form
    13     {
    14         public Form3()
    15         {
    16             InitializeComponent();
    17         }
    18 
    19         private void Form3_Load(object sender, EventArgs e)
    20         {
    21             textBox1.Text = Form2.right.ToString();
    22             textBox2.Text = Form2.count.ToString();
    23             textBox3.Text = ((Form2.right / (double)(Form2.count)) * 100).ToString() + "%";
    24         }
    25     }
    26 }
  • 相关阅读:
    Mybatis异常There is no getter for property named 'XXX' in 'class java.lang.String'
    js javascript 容错处理代码屏蔽js错误
    springmvc访问项目默认先访问后台再返回首页
    杂记-格式化Date默认格式,日期加一天,jstl判断字符类型,ajax模拟from表单后台跳转页面,jstl访问数据库并在页面显示
    测试覆盖率工具EclEmma安装与使用
    GSON使用之对特殊字符的转换的处理
    eclipse启动自己添加的tomcat时tomcat的webapps下没有项目
    接口和抽象类
    枚举
    Java异常
  • 原文地址:https://www.cnblogs.com/zwt0626/p/4995630.html
Copyright © 2011-2022 走看看