zoukankan      html  css  js  c++  java
  • (深入.Net平台和C#编程)第六章上机练习4.李向阳.20170411

     1 ==============加法类================
     2 using System;
     3 using System.Collections.Generic;
     4 using System.Linq;
     5 using System.Text;
     6 using System.Threading.Tasks;
     7 
     8 namespace Sj4.Entity
     9 {
    10     /// <summary>
    11     /// 加法
    12     /// </summary>
    13     public class Jiafa : Operation
    14     {
    15         //计算方法
    16         public override double GetResult()
    17         {
    18             if (NumberB == 0)
    19             {
    20                 throw new Exception("不能为0");
    21             }
    22             double result = NumberA + NumberB;
    23             return result;
    24         }
    25     }
    26 }
    View Code
     1 ============减法类============
     2 using System;
     3 using System.Collections.Generic;
     4 using System.Linq;
     5 using System.Text;
     6 using System.Threading.Tasks;
     7 
     8 namespace Sj4.Entity
     9 {
    10     /// <summary>
    11     /// 减法
    12     /// </summary>
    13     public class Jianfa : Operation
    14     {
    15         //计算方法
    16         public override double GetResult()
    17         {
    18             double result = NumberA - NumberB;
    19             return result;
    20         }
    21     }
    22 }
    View Code
     1 =========乘法类===============
     2 using System;
     3 using System.Collections.Generic;
     4 using System.Linq;
     5 using System.Text;
     6 using System.Threading.Tasks;
     7 
     8 namespace Sj4.Entity
     9 {
    10     /// <summary>
    11     /// 乘法类
    12     /// </summary>
    13     public class Cehng : Operation
    14     {
    15         //计算方法
    16         public override double GetResult()
    17         {
    18             if (NumberA == 0)
    19             {
    20                 throw new Exception("不能为0");
    21             }
    22             double result = NumberA * NumberB;
    23             return result;
    24         }
    25     }
    26 }
    View Code
     1 ===============除法类==============
     2 using System;
     3 using System.Collections.Generic;
     4 using System.Linq;
     5 using System.Text;
     6 using System.Threading.Tasks;
     7 
     8 namespace Sj4.Entity
     9 {
    10     /// <summary>
    11     /// 除法
    12     /// </summary>
    13     public class Chufa : Operation
    14     {
    15         //计算方法
    16         public override double GetResult()
    17         {
    18             if (NumberB == 0)
    19             {
    20                 throw new Exception("不能为0");
    21             }
    22             double result = NumberA / NumberB;
    23             return result;
    24         }
    25     }
    26 }
    View Code
     1 ================测试类==================
     2 using System;
     3 using System.Collections.Generic;
     4 using System.ComponentModel;
     5 using System.Data;
     6 using System.Drawing;
     7 using System.Linq;
     8 using System.Text;
     9 using System.Threading.Tasks;
    10 using System.Windows.Forms;
    11 using Sj4.Entity;
    12 
    13 namespace Sj4
    14 {
    15     public partial class FrmMain : Form
    16     {
    17         public FrmMain()
    18         {
    19             InitializeComponent();
    20         }
    21         //加载事件
    22         private void FrmMain_Load(object sender, EventArgs e)
    23         {
    24             cmbAdd();
    25         }
    26         /// <summary>
    27         /// 添加运算符
    28         /// </summary>
    29         public void cmbAdd()
    30         {
    31             cmbList.Text = "+";
    32             cmbList.Items.Add("-");
    33             cmbList.Items.Add("*");
    34             cmbList.Items.Add("/");
    35         }
    36         /// <summary>
    37         /// 计算点击事件
    38         /// </summary>
    39         /// <param name="sender"></param>
    40         /// <param name="e"></param>
    41         private void btnJiSuan_Click(object sender, EventArgs e)
    42         {
    43             if (string.IsNullOrEmpty(txt1.Text.Trim()) && string.IsNullOrEmpty(txt2.Text.Trim()))
    44             {
    45                 MessageBox.Show("不能为空");
    46             }
    47             Operation bb = new Operation();
    48             switch (cmbList.Text.Trim())
    49             {
    50                 case "+":
    51                     bb = new Jiafa();
    52                     break;
    53                 case "-":
    54                     bb = new Jianfa();
    55                     break;
    56                 case "/":
    57                     bb = new Chufa();
    58                     break;
    59                 case "*":
    60                     bb = new Cehng();
    61                     break;
    62             }
    63             bb.NumberA = double.Parse(txt1.Text.Trim());
    64             bb.NumberB = double.Parse(txt2.Text.Trim());
    65             this.lblJg.Text = bb.GetResult().ToString();
    66         }
    67     }
    68 }
    View Code

  • 相关阅读:
    linux tftp 服务
    AtomicInteger
    深入理解JVM(三)——垃圾收集策略具体解释
    Android 虚拟现实(virtual reality)入门指南
    Java千百问_05面向对象(005)_接口和抽象类有什么差别
    postman发送json格式的post请求
    什么是Session分布式共享
    如何设计一个单点登录系统(3)?
    如何设计一个单点登录系统(2)?
    如何设计一个单点登录系统(1)?
  • 原文地址:https://www.cnblogs.com/qq2835200767/p/6691802.html
Copyright © 2011-2022 走看看