| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1323 人关注过本帖
标题:代码没错,输出错误,能看看怎么回事吗?
只看楼主 加入收藏
a154734817
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2020-11-16
结帖率:100%
收藏
 问题点数:0 回复次数:0 
代码没错,输出错误,能看看怎么回事吗?
public abstract class Employee
    {
        public string name { get; set; }
        public decimal earnings { get; set; }   
        public DateTime bornDay { get; set; }   
        public abstract string Type { get; }               
        public Employee() { }
        public Employee(string nm, int year, int month, int day)
        {
            name = nm;
            bornDay = new DateTime(year, month, day);
        }
        public abstract void Earnings();
        public virtual void Display()
        {
            Console.WriteLine("职工名字:{0},出生日期:{1},职务:{2},工资:{3}", name, bornDay.ToString("yyyy//MM/dd"), Type, earnings.ToString("C2"));
        }
    }
    public class Manager : Employee
    {
        public double salary;     
        public double bonus;
        public Manager() { }
        public Manager(string nm, int year, int month, int day, double sl, double bns) : base(nm, year, month, day)
        {
            salary = sl;
            bonus = bns;
        }
        public override void Earnings()
        {
            earnings = (decimal)(salary + bonus);
        }
            public override string Type
        {
            get { return Type; }
        }
        public override void Display()
        {
            base.Display();
            Console.WriteLine("基本工资:{0},资金:{1}.", salary.ToString("C2"), bonus.ToString("C2"));
        }
    }
        public class salesman:Employee
        {
            public float salary,commission;
            const float RATE=0.05F;
            public salesman(string nm, int year, int Month, int day, float sl, float c)
                : base(nm, year, Month, day)
            {
                salary = sl;
                commission = c;
            }
            public override  string Type
            {
                get { return "销售员"; }
            }
            public override void Earnings()
            {
             Console.WriteLine("earnings:{0:c2}",salary + commission * RATE);
            }
            public override void Display()
            {
                base.Display();
                Console.WriteLine("基本工资:{0:f2}¥,销售额:{1:f2}¥", salary, commission);
                Console.WriteLine("提成率:{0}%", RATE);
            }
        }
        public class Timeworker : Employee
        {
            public readonly int hourwage = 15;
            public int hours;
            public Timeworker(string nm, int year, int Month, int day, int h)
                : base(nm, year, Month, day)
            {
                hours = h;
            }
            public override  string Type
            {
                get { return "计时工人"; }
            }
            public override void Earnings()
            {
            Console.WriteLine("earnings:{0:c2}",hourwage * hours + (hours - 40) * 1.5);
            }
            public override void Display()
            {
                base.Display();
                Console.WriteLine("每小时工资:{0:f2}¥,工作小时数:{1}", hourwage, hours);
            }
        }
        class Pieceman : Employee
        {
            public readonly int picePay = 15;
            public int no;
            public Pieceman(string nm, int year, int Month, int day, int o)
                : base(nm, year, Month, day)
            {
                no = o;
            }
            public override  string Type
            {
                get { return "计件工人"; }
            }
            public override void Earnings()
            {
                earnings = picePay * no;
            }
            public override void Display()
            {
                base.Display();
                Console.WriteLine("每件工资:{0:f2}¥,产品件数:{1}", picePay, no);
            }
        }
        public class test
        {
        static void Main(string[] args)
        {
            Manager M = new Manager("王云", 2001, 01, 15, 10000, 1500);
            salesman S = new salesman("郑凯", 2000, 09, 02, 6000, 3000);
            Timeworker T = new Timeworker("张翔", 2000, 03, 17, 3000);
            Pieceman P = new Pieceman("张权", 2000, 02, 25, 300000);
            M.Earnings();
            M.Display();
            S.Earnings();
            S.Display();
            T.Earnings();
            T.Display();
            P.Earnings();
            P.Display();
        }
    }
}
搜索更多相关主题的帖子: string override int public Display 
2020-11-22 22:49
快速回复:代码没错,输出错误,能看看怎么回事吗?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.019143 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved