WorkPaymentCalculator.cs 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. using System;
  2. using System.Collections.Generic;
  3. namespace FirstLibrary
  4. {
  5. public class WorkPaymentCalculator
  6. {
  7. public class WorkDay
  8. {
  9. public DateTime Date { get; set; }
  10. public int HourCount { get; set; }
  11. }
  12. public static double CalculateSalary(double hourSalary, List<WorkDay> workDays, int experience)
  13. {
  14. double salary = 0;
  15. double kExperience = (experience < 5)? 1d : (experience >= 5 && experience < 10)? 1.1d : 1.2d;
  16. foreach (WorkDay workDay in workDays)
  17. {
  18. double daySalary = 0;
  19. bool isHolyday = workDay.Date.DayOfWeek == DayOfWeek.Sunday || workDay.Date.DayOfWeek == DayOfWeek.Saturday;
  20. if(workDay.HourCount > 8)
  21. daySalary = 8 * hourSalary * (isHolyday ? 2 : 1) + (workDay.HourCount - 8) * hourSalary * 2 * (isHolyday ? 2 : 1);
  22. else
  23. daySalary = workDay.HourCount * hourSalary * (isHolyday ? 2 : 1);
  24. salary += daySalary;
  25. }
  26. return salary * kExperience;
  27. }
  28. }
  29. }