第六章,上机练习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 SJ3_4
 8 {
 9     class Program
10     {
11         static void Main(string[] args)
12         {
13             List<Employee> empls = new List<Employee>();
14             SE Joe=new SE("杰克",20,100);
15             SE ai = new SE("艾边成", 25, 200);
16             PM pm = new PM("艾斯", 30, 10);
17             empls.Add(Joe);
18             empls.Add(ai);
19             empls.Add(pm);
20             //foreach (Employee item in empls)
21             //{
22             //      Console.WriteLine(item.SayHi());
23             //}
24             for (int i = 0; i < empls.Count; i++)
25             {
26                 Console.WriteLine(empls[i].SayHi());
27             }
28         }
29     }
30 }
 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 using System.Threading.Tasks;
 6 
 7 namespace SJ3_4
 8 {
 9     public class Employee
10     {
11         //姓名
12         public string Name { get; set; }
13         public int Age { get; set; }
14         public virtual string SayHi() 
15         {
16             string message = string.Format("大家好");
17             return message;
18         }
19         /// <summary>
20         /// 构造函数
21         /// </summary>
22         public Employee(string name,int age) 
23         {
24             this.Name = name;
25             this.Age = age;
26         }
27     }
28 }
 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 using System.Threading.Tasks;
 6 
 7 namespace SJ3_4
 8 {
 9     /// <summary>
10     /// 经理类
11     /// </summary>
12     public class PM:Employee
13     {
14         //管理经验
15         public int YesarOfExperience { get; set; }
16         //构造函数
17         public PM(string name, int age, int yesarOfExperience): base(name, age)
18         {
19             this.YesarOfExperience = yesarOfExperience;
20         }
21         public override string SayHi() 
22         {
23             string message;
24             message = string.Format("大家好,我是{0},今年{1},管理经验是{0}", this.Name, this.Age, this.YesarOfExperience);
25             return message;
26         }
27     }
28 }
 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 using System.Threading.Tasks;
 6 
 7 namespace SJ3_4
 8 {
 9     /// <summary>
10     /// 程序员类
11     /// </summary>
12     public class SE:Employee
13     {
14         //人气
15         public int Popularity { get; set; }
16         public SE(string name, int age, int popularity) : base(name,age) 
17         {
18             this.Popularity = popularity;
19         }
20         /// <summary>
21         /// SayHi
22         /// </summary>
23         /// <returns></returns>
24         public override string SayHi() 
25         {
26             string message;
27             message= string.Format("大家好,我是{0},今年{1},人气是{0}", this.Name, this.Age, this.Popularity);
28             return message;
29         }
30     }
31 }

 

posted on 2017-04-11 01:09  yjh`  阅读(261)  评论(0编辑  收藏  举报

导航