Advertisement
shady_obeyd

03.Mankind-Worker.cs

Feb 27th, 2018
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.87 KB | None | 0 0
  1. using System;
  2. using System.Text;
  3.  
  4. public class Worker : Human
  5. {
  6.     public const decimal MinWeekSalary = 11.0m;
  7.     public const decimal MinHours = 1.0m;
  8.     public const decimal MaxHours = 12.0m;
  9.  
  10.     private decimal weekSalary;
  11.  
  12.     public decimal WeekSalary
  13.     {
  14.         get { return weekSalary; }
  15.         protected set
  16.         {
  17.             if (value < MinWeekSalary)
  18.             {
  19.                 throw new ArgumentException(GetErrotMessage("weekSalary"));
  20.             }
  21.             weekSalary = value;
  22.         }
  23.     }
  24.  
  25.     private decimal hoursPerDay;
  26.  
  27.     public decimal HoursPerDay
  28.     {
  29.         get { return hoursPerDay; }
  30.         protected set
  31.         {
  32.             if (value < MinHours || value > MaxHours)
  33.             {
  34.                 throw new ArgumentException(GetErrotMessage("workHoursPerDay"));
  35.             }
  36.             hoursPerDay = value;
  37.         }
  38.     }
  39.  
  40.     public decimal SalaryPerHour
  41.     {
  42.         get { return this.GetSalaryPerHour(); }
  43.     }
  44.  
  45.     public Worker(string firstName, string lastName, decimal weekSalary, decimal hoursPerDay) : base(firstName, lastName)
  46.     {
  47.         WeekSalary = weekSalary;
  48.         HoursPerDay = hoursPerDay;
  49.     }
  50.  
  51.     public override string ToString()
  52.     {
  53.         StringBuilder builder = new StringBuilder();
  54.  
  55.         builder.AppendLine(base.ToString());
  56.         builder.AppendLine($"Week Salary: {WeekSalary:f2}");
  57.         builder.AppendLine($"Hours per day: {HoursPerDay:f2}");
  58.         builder.AppendLine($"Salary per hour: {SalaryPerHour:f2}");
  59.  
  60.         return builder.ToString().TrimEnd();
  61.     }
  62.  
  63.     private string GetErrotMessage(string argument)
  64.     {
  65.         return $"Expected value mismatch! Argument: {argument}";
  66.     }
  67.  
  68.     private decimal GetSalaryPerHour()
  69.     {
  70.         decimal salaryPerDay = WeekSalary / 5.0m;
  71.  
  72.         return salaryPerDay / HoursPerDay;
  73.     }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement