1创建Employee类,包括三个实例变量:名字(string类型)、姓氏(string类型)和月薪(decimal)。类的构造函数要初始化这些实例变量。对每个实例变量提供一个属性,包括get和set方法。如果月薪为负值,则保持不变。写一个测试程序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);
}
}
}