Google
 

This page allows you to see two different ways to solve a problem:
- traditionally, using algorithmic representations given here as a model desribed in pseudocode and as a graphycal representation, process flowchart (program flowchart) and as implementation in Python and Visual Basic;
- modern, using Business Rules, as a natural way to describe our knowledge, as required by the Knowledge Society. The implementation is realized by intemediate of the product ARulesXL.

Natural Description: Solving Problems - Using Business Rules of ARulesXl Rules Engine
«The Payroll Problem»


Click to open the tutorial and download the spreadsheet sample: Open the page containing the steps you must follow to realize that solution or to download an example, a spreadsheet (in Excel), implementing that solution. To see the spreadsheet at work you must have installed ARulesXL, otherwise this do not react to changes.
The formulation of the problem is the one here, down. You can make a comparison what is the diference betwee the algorithmic solution and the one with business rules (the foundation for IT management solution for Knowledge Management), the Payroll Problem modeled with rules.

Pseudocode/ Flowchart: Solving Problems - Algorithms Representation
«The Payroll Problem»



Theme Formulation


In Romania, for full-time employees, during normal working hours is 8 hours per day and 40 hours per week (MaxNoOvertime). For all hours worked in a week over ( these 40 hours a week) the company must pay its employee (with overtime working) one time and half (BonusRate) the normal salary per hour. The employees that earn a salary more than 150€ per week must pay a supplemental tax  of 25% (due) from what is more than 150€ (MaxNoDue).

Requirement


Write a pseudocode/flowchart to compute an employee's overtime pay and net pay.
 

A Solution to the problem

We know:
    MaxNoOvertime=40h
    BonusRate=1.5
    MaxNoDue=150€
    Due=25%


         We want:
               GrossPay=?
               NetPay=?



We need to supply to the algorithm the values for:
     HoursWorked
     HourRate


A) A pseudocode solution

Steps:

S1. Start;
S2. Initialize the known variables: max hours worked with no overtime (MaxNoOvertime), bonus rate for overtime hours (BonusRate),
non taxable payroll amount (MaxNoDue), tax rate (Due);
S3. Enter hours worked overtime (HoursWorked) and hourly rate (HourRate);
S4. If (HourWorked-MaxNoOvertime)<=0 Then
    GrossPay=HoursWorked*HourRate;
  Else
    GrossPay=HourRate*(MaxNoOvertime + BonusRate*(HoursWorked-MaxNoOvertime));
S5. If GrossPay<=MaxNoDue Then
    NetPay=GrossPay;
  Else
    NetPay=GrossPay-Due*(GrossPay-MaxNoDue);
S6. Display GrossPay, NetPay;
S7. End.



B) A flowchart solution

A  flowchart representation of the algorithm for the Payroll Problem can be:

A flowcart algorithm for the Payroll problem


C) An Implementation Solution in Python


def payroll(HoursWorked=0.0,HourRate=0.0):
    # to prevent usage of integral division
    # a simple way to convert integer argument passed
    # at runtime and we prepare the input parameters
    HoursWorked = 1.0 * HoursWorked
    HourRate = 1.0 * HourRate
    # initialize the known variables
    MaxNoOvertime=40
    BonusRate=1.5
    MaxNoDue=150.00
    Due=0.25
    # processing
    if (HoursWorked-MaxNoOvertime)<=0:
        GrossPay=HoursWorked*HourRate
    else:
        GrossPay=HourRate*(MaxNoOvertime+BonusRate*(HoursWorked-MaxNoOvertime))
    if GrossPay<=MaxNoDue:
        NetPay=GrossPay
    else:         NetPay=GrossPay-Due*(GrossPay-MaxNoDue)
    print ("Gross pay="+ str(GrossPay)+'\nNet pay ='+str(NetPay)+"\nTax Val. ="+str(GrossPay-NetPay))


Here is a capture of the call of the payrol function and what the user see as output:
The output of the payroll.py function


D) An Implementation Solution in Visual Basic

Public Class PayrollForm
   Private Sub HoursWorked_TextChanged() Handles HoursWorked.TextChanged
   If HoursWorked.Text > MaxNoOvertime.Text Then
      GrossPay.Text = Val(HourRate.Text) * (Val(MaxNoOvertime.Text) + _       Val(BonusRate.Text) * (Val(HoursWorked.Text) - Val(MaxNoOvertime.Text)))
   Else
      GrossPay.Text = Val(HourRate.Text) * Val(HoursWorked.Text)
   End If
   If Val(GrossPay.Text) <= Val(MaxNoDue.Text) Then
      NetPay.Text = Val(GrossPay.Text)
   Else
      NetPay.Text = Val(GrossPay.Text) - Val(Due.Text) * (Val(GrossPay.Text) - Val(MaxNoDue.Text))
   End If
   TaxVal.Text = Val(GrossPay.Text) - Val(NetPay.Text)
   End Sub
   Private Sub MaxNoOvertime_TextChanged() Handles MaxNoOvertime.TextChanged
      HoursWorked_TextChanged()
   End Sub
   Private Sub MaxNoDue_TextChanged() Handles MaxNoDue.TextChanged
      HoursWorked_TextChanged()
   End Sub
   Private Sub BonusRate_TextChanged() Handles BonusRate.TextChanged
      HoursWorked_TextChanged()
   End Sub
   Private Sub Due_TextChanged() Handles Due.TextChanged
     HoursWorked_TextChanged()
   End Sub
End Class
The event procedures are associated to the controls in the following form:
The Visual Basic Solution
The predefined values are given as default values for the corresponding controls. They will have the defined value at each new start. The user can change a value during a session and this will be taken in consideration for all subjacent computations. Normally the only two values a user must supply are those for "Hours Worked" and "Hourly Rate" fields. Any change, during a session, of a value - predefined or currently required - starts automatically the re-evaluation of the outputs. The solution exploits the event _TextChange.






 

Copyright © 2006-2008 Vasile Avram

Valid CSS! Valid HTML 4.01 Transitional Cynthia Tested! Level Triple-A conformance icon, W3C-WAI Web Content Accessibility Guidelines 1.0