Note: This is a general programming question, not specific to any language, but feel free to use the language of your choice in your answer to explain the logic.
I would like a method to take a string of text, say "Default(0-100)=20" and then extract out of that the default hourly wage would be 20 for hours 0 through 100. This could be then used for say “Default(101-245)=25” that the default hourly wage for hours 101 through 245 would be 25. Also allow it to define “Brian(0-29)=15” that the user “Brian” would have an non-default hourly wage of 15 for hours 0 through 29.
My first impression is to run the string through a regular expression says something like ^(\w*)\((\d*)-(\d*)\)$ where it could pickup the Text and the smaller and higher end of the range.
What would be the best way to store this information so it could be used later on? multidimensional array? hashes?
Once you do have the information stored, what would be the best way of actually using the information to good use?
How would you calculate the total wages earned if say we used "Default(0-100)=20" & "Default(101-245)=25" and the number of hours worked was 150.
I think type of storage and regular expressions would be the least of your concerns in modeling this. You are essentially writing a simple rule engine to compute the salary of an employee. Figuring out what those rules is the most important part of this problem. Ensuring that rules are complete, consistent, and deterministic is another important piece. By deterministic, I mean you cannot have two rules like:
as the system does not know how to compute the wages for hours 50-100 since there are two choices. By complete, I mean the rules should be able to compute the wages given any employee and the number of hours they worked. Take another example:
If an employee worked for 150 hours, the system does not know their earned wages for hours 101-125. So incompleteness is another problem.
Assuming the rules are complete and deterministic, we can proceed with modeling. If hours worked can be fractional, then the solution will need to proportionally split the hourly wage. It looks like there is a default salary and then salaries specific to an employee. Salaries specific to an employee always take precedence over the default salary. So in a simple if-else pseudo-code, it would look like:
Checkout this article that gives one approach to writing a rule engine and interestingly it uses employees and wages as an example, so it might be helpful.
Some more interesting articles about rule engines that you might find useful: