Created
January 1, 2013 00:17
-
-
Save SyntaxC4/4424093 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public override float Calculate() | |
| { | |
| return CalculateOverTimeHours(HoursWorked, 52, | |
| x => x * OvertimeRates.Double_Time_And_A_Half) + | |
| base.Calculate(); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Developer: Cory Fowler | |
| // Company: SyntaxC4 Development Services | |
| // Description: Adds Type Safety and Saves Memory over Class | |
| namespace WageCalculator.Abstractions | |
| { | |
| public struct OvertimeRates | |
| { | |
| public const float Regular = 1.0f; | |
| public const float Time_And_A_Half = 1.5f; | |
| public const float Double_Time = 2.0f; | |
| public const float Double_Time_And_A_Half = 2.5f; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Developer: Cory Fowler | |
| // Company: SyntaxC4 Development Services | |
| // Description: Calculates Regular Time Rates for Employees | |
| namespace WageCalculator.Concrete | |
| { | |
| public class SalaryWageCalculator : Abstractions.WageCalculatorBase | |
| { | |
| #region ctor | |
| public SalaryWageCalculator(float hours, float hourlyRate) : | |
| base(hours, hourlyRate) { } | |
| #endregion | |
| public override float Calculate() | |
| { | |
| return HoursWorked * HourlyRate; | |
| } | |
| public static float Calculate(float hours, float hourlyRate) | |
| { | |
| return new SalaryWageCalculator(hours, hourlyRate).Calculate(); | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Developer: Cory Fowler | |
| // Company: SyntaxC4 Development Services | |
| // Description: Adds Functionality for OverTime Wage Calculation | |
| namespace WageCalculator.Concrete | |
| { | |
| #region Usings | |
| using Abstractions; | |
| #endregion | |
| public class TimeAndAHalfWageCalculator : WageCalculatorBase | |
| { | |
| public const float MAXIMUM_HOURS_BEFORE_TIME_AND_A_HALF = 40; | |
| public TimeAndAHalfWageCalculator(float hours, float hourlyRate) : base(hours, hourlyRate){} | |
| public override float Calculate() | |
| { | |
| return (CalculateOverTimeHours(HoursWorked, | |
| MAXIMUM_HOURS_BEFORE_TIME_AND_A_HALF, | |
| x => x * OvertimeRates.Time_And_A_Half) + | |
| MAXIMUM_HOURS_BEFORE_TIME_AND_A_HALF) * HourlyRate; | |
| } | |
| public static float Calculate(float hours, float hourlyRate) | |
| { | |
| return new TimeAndAHalfWageCalculator(hours, hourlyRate).Calculate(); | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Developer: Cory Fowler | |
| // Company: SyntaxC4 Development Services | |
| // Description: Exposes Common Functionality to WageCalculators. | |
| namespace WageCalculator.Abstractions | |
| { | |
| #region Usings | |
| using System; | |
| #endregion | |
| public abstract class WageCalculatorBase | |
| { | |
| public float HoursWorked { get; private set; } | |
| public float HourlyRate { get; private set; } | |
| public const float MAXIMUM_HOURS_PER_WEEK = 80f; | |
| public const float MINIMUM_HOURS_PER_WEEK = 0f; | |
| public WageCalculatorBase(float hours, float hourlyRate) | |
| { | |
| if (hours < MINIMUM_HOURS_PER_WEEK || hours > MAXIMUM_HOURS_PER_WEEK) | |
| // Should Probably Create WorkWeekOutOfRangeException | |
| throw new ArgumentOutOfRangeException(string.Format("Hours must be between {0} and {1}", | |
| MINIMUM_HOURS_PER_WEEK, | |
| MAXIMUM_HOURS_PER_WEEK)); | |
| HoursWorked = hours; | |
| HourlyRate = hourlyRate; | |
| } | |
| protected float CalculateOverTimeHours(float hours, | |
| float overtimeThreshold, | |
| Func<float, float> calculateOvertimePay) | |
| { | |
| return calculateOvertimePay(hours - overtimeThreshold); | |
| } | |
| public abstract float Calculate(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment