我无法获得总薪酬(我相信我计算它的方法是错误的)。任何帮助都表示赞赏,特别是以外行术语解释。我希望能够更好地理解为什么以及如何运作。 到目前为止,我有以下类(使用我的main方法与类分开):
namespace Project
{
class Employee
{
public string FirstName { get; set; }
public string LastName { get; set; }
private decimal RateOfPay { get; set; }
public string JobTitle { get; set; }
public string HireDate { get; set; }
//constructor
public Employee (string firstName, string lastName, decimal
rateOfPay, string jobTitle, string hireDate)
{
FirstName = firstName;
LastName = lastName;
RateOfPay = rateOfPay;
JobTitle = jobTitle;
HireDate = hireDate;
}
public decimal Salary
{
//IS THIS HOW I WOULD CALCULATE THE "GROSS"? AS IN WAGE * HOURS?
get { return RateOfPay; }
set { RateOfPay = (value * 40); }
}
}
}
然后,在我的主要方法的单独课程中,我有:
namespace EmployeeClass
{
class Program
{
static void Main(string[] args)
{
Employee empl1 = new Employee("Robert", "Smith", (decimal)50.00,
"Associate", "5/5/2016");
Employee empl2 = new Employee("Bill", "Hicks", (decimal)70.00,
"Manager", "7/12/2013");
Console.WriteLine("Employee 1 First Name: {0}", empl1.FirstName);
Console.WriteLine("Employee 1 Last Name: {0}", empl1.LastName);
Console.WriteLine("Employee 1 Rate of Pay: {0:C}", empl1.Salary);
Console.WriteLine("Employee 1 Job Title: {0}", empl1.JobTitle);
Console.WriteLine("Employee 1 Hire Date: {0}", empl1.HireDate);
Console.WriteLine("Employee 2 First Name: {0}", empl2.FirstName);
Console.WriteLine("Employee 2 Last Name: {0}", empl2.LastName);
Console.WriteLine("Employee 2 Rate of Pay: {0:C}", empl2.Salary);
Console.WriteLine("Employee 2 Job Title: {0}", empl2.JobTitle);
Console.WriteLine("Employee 2 Hire Date: {0}", empl2.HireDate);
Console.ReadLine();
}
}
}
如何获得输出显示工资乘以40小时?再次,请使用LAYMAN条款!提前谢谢!
答案 0 :(得分:1)
您将工资率(每小时赚取的金额)与总工资(即您获得的总金额)相混淆。
当您存储RateOfPay时,您应该只存储并返回RateOfPay,并为Salary提供单独的函数,该函数将采用小时数的参数。
public decimal Salary(decimal Hours)
{
return RateOfPay * Hours;
}