zoukankan      html  css  js  c++  java
  • 第六章,上机3

     1 using System;
     2 using System.Collections.Generic;
     3 using System.Linq;
     4 using System.Text;
     5 using System.Threading.Tasks;
     6 
     7 namespace WindowsFormsApplication1
     8 {
     9     public class Employee
    10     {
    11         public int Age { get; set; }
    12         public Gender Gender { get; set; }
    13         public string ID { get; set; }
    14         public string Name { get; set; }
    15         protected List<Job> WorkList { get; set; }
    16         public Employee(string id, int age, string name, Gender gender, List<Job> list)
    17         {
    18             this.ID = id;
    19             this.Age = age;
    20             this.Name = name;
    21             this.Gender = gender;
    22             this.WorkList = list;
    23         }
    24         public virtual string DoWork()
    25         {
    26             return "";
    27         }
    28     }
    29 }
    父类
     1 using System;
     2 using System.Collections.Generic;
     3 using System.Linq;
     4 using System.Text;
     5 using System.Threading.Tasks;
     6 
     7 namespace WindowsFormsApplication1
     8 {
     9     public enum Gender
    10     {
    11         男,
    12 13     }
    14 }
    枚举类
     1 using System;
     2 using System.Collections.Generic;
     3 using System.Linq;
     4 using System.Text;
     5 using System.Threading.Tasks;
     6 
     7 namespace WindowsFormsApplication1
     8 {
     9     public class Job
    10     {
    11         public string Name { get; set; }
    12         public string Description { get; set; }
    13 
    14         public Job(string name, string description)
    15         {
    16             this.Name = name;
    17             this.Description = description;
    18         }
    19     }
    20 }
    Job
     1 using System;
     2 using System.Collections.Generic;
     3 using System.Linq;
     4 using System.Text;
     5 using System.Threading.Tasks;
     6 
     7 namespace WindowsFormsApplication1
     8 {
     9     public class PM:Employee
    10     {
    11         public int YearOfExperience { get; set; }
    12         public override string DoWork()
    13         {
    14             string message = this.Name + "管理员完成工作内容!";
    15             return message;
    16         }
    17         public PM(string id, int age, string name, Gender gender, List<Job> list, int yearOfExperience)
    18             : base(id, age, name, gender, list)
    19         {
    20             this.YearOfExperience = yearOfExperience;
    21         }
    22     }
    23 }
    PM类
     1 using System;
     2 using System.Collections.Generic;
     3 using System.Linq;
     4 using System.Text;
     5 using System.Threading.Tasks;
     6 
     7 namespace WindowsFormsApplication1
     8 {
     9     public class SE:Employee
    10     {
    11         public int _popularity;
    12         public int Popularity { get; set; }
    13         public override string DoWork()
    14         {
    15             StringBuilder sb = new StringBuilder();
    16             sb.Append(this.Name + ":
    ");
    17             for (int i = 0; i < this.WorkList.Count; i++)
    18             {
    19                 sb.Append((i + 1) + "" + WorkList[i].Name + ":" + WorkList[i].Description + "
    ");
    20             }
    21             return sb.ToString();
    22         }
    23         public SE(string id, int age, string name, Gender gender, List<Job> list, int popularity)
    24             : base(id, age, name, gender, list)
    25         {
    26             this.Popularity = popularity;
    27         }
    28     }
    29 }
    SE类
     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.Threading.Tasks;
     9 using System.Windows.Forms;
    10 
    11 namespace WindowsFormsApplication1
    12 {
    13     public partial class FrmMain : Form
    14     {
    15         public FrmMain()
    16         {
    17             InitializeComponent();
    18             Init();
    19         }
    20         //员工集合
    21         List<Employee> empls = new List<Employee>();
    22         //员工信息初始化
    23         public void Init()
    24         {
    25             //实例化SE对象
    26             List<Job> list1 = new List<Job>();
    27             list1.Add(new Job("编码", "购物车模块"));
    28             list1.Add(new Job("测试", "给购物车模块做单元测试"));
    29             SE yu = new SE("112", 17, "俞++", Gender.男, list1, 100);
    30 
    31             List<Job> list2 = new List<Job>();
    32             list2.Add(new Job("设计", "数据库建模"));
    33             list2.Add(new Job("编写文档", "详细设计说明书"));
    34             SE joe = new SE("111", 25, "Joe", Gender.男, list2, 200);
    35 
    36             //实例化PM对象
    37             PM pm = new PM("809", 50, "盖茨", Gender.男, null, 30);
    38             empls.Add(yu);
    39             empls.Add(joe);
    40             empls.Add(pm);
    41         }
    42 
    43         private void btnRender_Click(object sender, EventArgs e)
    44         {
    45             foreach (Employee emp in empls)
    46             {
    47                 MessageBox.Show(emp.DoWork(), "汇报");
    48             }
    49         }
    50 
    51     }
    52 }
    Main
  • 相关阅读:
    php基本语法
    php的环境搭建
    Java数组及其内存分配
    最快的maven镜像
    配置maven到运行
    配置maven
    maven的eclise配置
    mysql中bit_count和bit_or函数的含义
    怎样查看MySQL是否区分大小写
    linux忘记mysql密码找回方法
  • 原文地址:https://www.cnblogs.com/lzx666/p/6691767.html
Copyright © 2011-2022 走看看