Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>im not very experienced, but im trying to answer it for myself, maybe it can help you.</p> <p>To the first part of your question, for a string like that id simply split the given string at the apropriate positions. most frameworks have classes to do this. in your case for example that would be ( ) - and =</p> <p>result:</p> <p>Default, (, 0, -, 100, ) , =, 20</p> <ol> <li>Default</li> <li>(</li> <li>0</li> <li>-</li> <li>100</li> <li>)</li> <li>=</li> <li>20</li> </ol> <p>youre values are always at the same index when you use a consistent stringformat. pick them, convert if needed and store in variables;</p> <p>assuming youre talking about object orientated programming i would do something like this in your case:</p> <p>create a class employee with name, and hourly-wages as instance variables. this class has also a method calculateWageForHours(int hours). the hourlywages could be stored in a dictionairy or sth simlilar - depending on your framework. You take the beginning-hour as key for the dict an the wagerate as value. you dont need the ending-hours since one rate consists until the next "stage" is reached.</p> <p>the method to calculate the wage could look sth like this:(there sure is a better way depending on the concrete situation)</p> <pre><code>calculateWageForHours(int hours) { for (int i = 0, i &lt; dict.count - 1, i++) { if (hours &lt; dict[i + 1].key /* the int-value for the hour */ -1) { float wage; for (int j = 0, j &lt; i, j++) { wage += (dict[j + 1].key - 1) * dict[j].value; } wage += (hours - dict[i].key - 1) * dict[i].value; return wage; } return calculateWageForHours(dict.lastkey - 1) + (hours - dict.lastkey) * dict.lastkey.value; </code></pre> <p>The default-part could be set anywhere in your programm where you instanciate the employee-class. just write a method which creates the default dictionairy for the employee. (could also be done in the object-initialisation and you hand in the nessesairy arguments from your controller-class)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload