第六章,上机2

时间:2023-02-10 13:27:00
第六章,上机2第六章,上机2
 1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 using System.Threading.Tasks;
6
7 namespace Shangji2
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 }
25 }
父类
第六章,上机2第六章,上机2
 1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 using System.Threading.Tasks;
6
7 namespace Shangji2
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类
第六章,上机2第六章,上机2
 1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 using System.Threading.Tasks;
6
7 namespace Shangji2
8 {
9 public enum Gender
10 {
11 男,
12
13 }
14 }
枚举类
第六章,上机2第六章,上机2
 1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 using System.Threading.Tasks;
6
7 namespace Shangji2
8 {
9 public class PM:Employee
10 {
11 public int YearOfExperience { get; set; }
12 public 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):base(id,age,name,gender,list)
18 {
19 this.YearOfExperience = yearOfExperience;
20 }
21 }
22 }
PM类
第六章,上机2第六章,上机2
 1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 using System.Threading.Tasks;
6
7 namespace Shangji2
8 {
9 public class SE:Employee
10 {
11 public int _popularity;
12 public int Popularity { get; set; }
13 public string DoWork()
14 {
15 StringBuilder sb = new StringBuilder();
16 sb.Append(this.Name+":\n");
17 for (int i = 0; i < this.WorkList.Count; i++)
18 {
19 sb.Append((i + 1) + "" + WorkList[i].Name + ":" + WorkList[i].Description + "\n");
20 }
21 return sb.ToString();
22 }
23 public SE(string id,int age,string name,Gender gender,List<Job> list,int popularity):base(id,age,name,gender,list)
24 {
25 this.Popularity = popularity;
26 }
27
28 }
29 }
SE类第六章,上机2第六章,上机2
 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 Shangji2
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 //汇报工作
44 private void btnRender_Click(object sender, EventArgs e)
45 {
46 foreach (Employee emp in empls)
47 {
48 if (emp is PM)
49 {
50 MessageBox.Show(((PM)emp).DoWork(),"汇报");
51 }
52 if (emp is SE)
53 {
54 MessageBox.Show(((SE)emp).DoWork(), "汇报");
55 }
56 }
57 }
58 }
59 }
Main