求助C#演示抽象类和接口的一个问题

问题:编写一个程序以演示抽象类和接口,要求如下:
(1)定义一个Employee抽象类,其中包含Name和Salary属性及Print()抽象方法。类似地,定义IPromotable和IGoodStudent两个接口,使它们都包含Promote()方法。
(2)从Employee()类派生出Shixi类,使其包含存储实习期的字段months。从Emphoyee类和IPromotable接口类派生出Programmer类,使其有存储加班时间的hours字段,并通过实现接口中的Promote()方法将薪水提高到1.5倍。
(3)从Employee类以及IPromotable和IGoodWorker接口派生出Manager类,使其具有存储秘书名字的mishu字段,并通过实现IPromotable接口中的Promote()方法将薪水提高到1.8倍,通过实现IGoodWorker接口中的Promote()方法输出经理职位晋升。派生类中重写Print()方法,输出职员的姓名和薪水,平均加班时间、秘书、加新后的薪水等信息。
编写一个程序以演示抽象类和接口,要求如下:
(1)定义一个Employee抽象类,其中包含Name和Salary属性及Print()抽象方法。类似地,定义IPromotable和IGoodStudent两个接口,使它们都包含Promote()方法。
(2)从Employee()类派生出Shixi类,使其包含存储实习期的字段months。从Emphoyee类和IPromotable接口类派生出Programmer类,使其有存储加班时间的hours字段,并通过实现接口中的Promote()方法将薪水提高到1.5倍。
(3)从Employee类以及IPromotable和IGoodWorker接口派生出Manager类,使其具有存储秘书名字的mishu字段,并通过实现IPromotable接口中的Promote()方法将薪水提高到1.8倍,通过实现IGoodWorker接口中的Promote()方法输出经理职位晋升。派生类中重写Print()方法,输出职员的姓名和薪水,平均加班时间、秘书、加新后的薪水等信息。
提示:两个接口包含相同名称的方法,注意体会显式接口实现的使用。程序运行结果如图1所示,类关系如图2所示。
代码:

using System;

namespace ConsoleApp8
{
    public abstract class Employee
    {
        protected String Name;
        protected double salary;
        abstract public void print();
    }
    public interface IPromotable
    {
        void Promote();
    }
    public interface IGoodWorker
    {
        void Promote();
    }
    public class Shixi : Employee
    {
        protected int months;
        public Shixi(String Name, int salary, int months)
        {
            this.Name = Name;
            this.salary = salary;
            this.months = months;
        }
        public override void print()
        {
            Console.WriteLine("实习生:  ");
            Console.WriteLine("姓名:  " + this.Name);
            Console.WriteLine("薪水:  " + this.salary);
            Console.WriteLine("实习期(月):  " + this.months);
        }
    }
    public class Programmer : Shixi, IPromotable
    {
        protected int hours;
        public Programmer(String Name, int salary, int hours):base(Name,salary,hours)
        {
            this.Name = Name;
            this.salary = salary;
            this.hours = hours;
        }
        public override void print()
        {
            Console.WriteLine("程序员");
            Console.WriteLine("姓名:" + this.Name);
            Console.WriteLine("薪水:" + this.salary);
            Console.WriteLine("平均加班时间:" + this.hours);
        }
        public void Promote()
        {
            Console.WriteLine("加班后的薪水:" + this.salary * 1.5);
        }
    }
    public class Manager : Programmer, IPromotable, IGoodWorker
    {
        protected int mishu;
        public Manager(String Name, int salary,int mishu):base(Name,salary,mishu)
        {
            this.Name = Name;
            this.salary = salary;
            this.mishu = mishu;
        }
        public override void print()
        {
            Console.WriteLine("经理");
            Console.WriteLine("姓名:" + this.Name);
            Console.WriteLine("薪水:" + this.salary);
            Console.WriteLine("秘书:" + this.mishu);
        }
        void IPromotable.Promote()
        {
            Console.WriteLine("加班后的薪水:" + this.salary * 1.8);
        }
        void IGoodWorker.Promote()
        {
            Console.WriteLine("经理是优秀的,所以获得职位的晋升");
        }
    }
    class program
    {
        static void Main(string[] args)
        {
            Shixi shixi = new Shixi("赵丰", 5500, 2);
            shixi.print();
            Console.WriteLine();

            Programmer programmer = new Programmer("张强", 45000, 4);
            programmer.print();
            IPromotable promotable = programmer;
            promotable.Promote();
            Console.WriteLine();

            Manager manager = new Manager("约翰", 120000, "玛丽");
            manager.print();
            IPromotable promotable1 = manager;
            IGoodWorker goodworker = manager;
            promotable1.Promote();
            goodworker.Promote();
        }
    }
}

问题:主方法里“玛丽”
CS1503 参数 3: 无法从“string”转换为“int”
不知道哪里错了

1个回答

public Manager(String Name, int salary,int mishu):base(Name,salary,mishu)
{
this.Name = Name;
this.salary = salary;
this.mishu = mishu;
}
Manager构造函数第三个字段时int类型,你传入的是Manager manager = new Manager("约翰", 120000, "玛丽");,“玛丽”转int失败,报这个错误没毛病

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问