C#习题练习第一弹!!

1创建Employee类,包括三个实例变量:名字(string类型)、姓氏(string类型)和月薪(decimal)。类的构造函数要初始化这些实例变量。对每个实例变量提供一个属性,包括getset方法。如果月薪为负值,则保持不变。写一个测试程序EmployeeTest,演示Employee的功能。创建两个Employee对象,显示每个对象的年薪,然后让每个员工提薪10%,再次显示每个对象的年薪。

源代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Employee
{
    class Employee1
    {
        private string fristName;
        private string familyName;
        private decimal salary;
        public Employee1(string fristName,string familyName,decimal salary)
        {
            this.fristName = fristName;
            this.familyName = familyName;
            this.salary = salary;
        }
        public void setFristName(string fristName)
        {
            this.fristName = fristName;
        }
        public string getFristName()
        {
            return this.fristName;
        }
        public void setFamilyName(string familyName)
        {
            this.familyName = familyName;
        }
        public string getFamilyName()
        {
            return this.familyName;
        }
        public void setSalary(decimal salary)
        {
            this.salary =salary;
        }
        public decimal getSalary()
        {
            return this.salary;
        }
        //实现 EmployeeTest方法。

        public void EmployeeTest(string f1name,string f2name,decimal salary)
        {
            decimal money = salary + salary * 0.1M;
            Console.WriteLine("其名字为"+f2name+f1name+"的年薪为:"+money);

        }
        static void Main(string[] args)
        {
            Employee1 e1 = new Employee1("明", "李", 346.4M);//初始化
            e1.EmployeeTest("明", "李", 346.4M);
            Employee1 e2 = new Employee1("行", "王", 376.4M);//初始化
            e2.EmployeeTest("行", "王", 356.4M);

        }
    }
}

 

2、开发一个c#程序,确定几个员工的总工资。公司对每个员工的前40小时发计时工资,此后发加班工资(原工资的1.5倍)。你可以得到一系列的公司员工名单、每个员工上周工作小时数和每个员工的小时工资。程序要输入每个员工的这些信息,确定和显示员工的总工资。用Console类的Readline方法输入。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Employee
{
    class Employee2
    {
        //定义属性
        private static string name;//员工姓名
        private static int hours;//上周工作小时数
        private static decimal salary;//每个员工的小时工资
        //调用方法计算员工的总工资;
        public void SumSlary(string name,int hours,decimal salary)
        {
            decimal item;
            item = salary * hours;
            Console.WriteLine("员工为"+name+"的总工资为:"+item);
        }

        static void Main(string[] args)
        {
            Employee2 e2 = new Employee2();
            Console.WriteLine("请输入员工的姓名");
            name = Console.ReadLine();
            Console.WriteLine("请输入员工上周工作的小时数");
            hours =int.Parse( Console.ReadLine());
            Console.WriteLine("请输入该员工的每小时工资");
            salary = decimal.Parse(Console.ReadLine());
            //调用方法实现要求
            e2.SumSlary(name,hours,salary);
        }
    }
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值