Write an algorithm for a program that includes an Employee class that can be used to calculate and print the take home pay for a commissioned sales employee. All Employee receives 7% of the total sales. Income tax rate is 18%. Retirement contribution is 10%. Social security tax is 6%. Write instance methods to calculate the commission, income tax and social security tax withholding amounts as well as the amount withheld for retirement. Use appropriate constants. Design an object oriented solution and write constructors. Include at least one mutator and one accessor method; provide properties for the other instance variables. Create a second class to test your design. Allow the user to enter values for the name of the employee and the sales amount for the week in the second class.
Declare class Employee
Declare constant TOTAL_SALES_RATE = 0.07
Declare constant INCOME_RATE = 0.18
Declare constant RETIREMENT_CONTRIBUTION = 0.1
Declare constant SOCIAL_SECURITY_TAX_RATE = 0.06
Declare variable name
Declare variable salesAmount
Declare property Name
Declare property SalesAmount
Declare constructor Employee()
Declare constructor Employee(name, salesAmount)
set name = name
set salesAmount = salesAmount
End constructor
Start function calculateCommission()
return this.salesAmount * TOTAL_SALES_RATE
End function
Start function calculateIncomeTax()
return this.salesAmount * INCOME_RATE
End function
Start function calculateRetirementContribution()
return this.salesAmount * RETIREMENT_CONTRIBUTION
End function
Start function calculateSocialSecurityTax()
return this.salesAmount * SOCIAL_SECURITY_TAX_RATE
End function
Start function calculateTotalPay()
return this.salesAmount + calculateCommission() - calculateIncomeTax() - calculateRetirementContribution() - calculateSocialSecurityTax()
End function
End class
Declare class Program
Start function Main(args)
Declare variable name
Declare variable salesAmount
Read name
Read salesAmount
Create Employee object employee(name, salesAmount)
Display "Commission (7%): "+ employee.calculateCommission()
Display "Income tax rate (18%): "+ employee.calculateIncomeTax()
Display "Retirement contribution (10%): "+ employee.calculateRetirementContribution()
Display "Social security tax (6%): "+ employee.calculateSocialSecurityTax()
Display "Total: "+ employee.calculateTotalPay()
Stop function
End class
Comments
Leave a comment