2017-07-29 73 views
-4

我無法獲得總產出(我的計算方法是錯誤的,我相信)。任何幫助表示讚賞,特別是在外行解釋。我正在更深入地瞭解爲什麼以及如何運作。 到目前爲止,我有下面的類(從類單獨與我的主要方法):我如何得到這個來計算總收入?

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條款!提前致謝!

回答

1

您將工資率(這是您每小時賺取的金額)與工資總額(這是您總共賺取的金額)相混淆。

當您存儲RateOfPay時,您應該只存儲並返回RateOfPay併爲Salary提供一個單獨的函數,該函數將採用小時數的參數。

public decimal Salary(decimal Hours) 
    { 
     return RateOfPay * Hours; 
    } 
相關問題