Exercise 4
Due: Monday, July 15, 11:59:59 PM EST.
Implement these exercises with the Beginning Student Language.
1 Directions for submitting
Please read and follow these intructions carefully. You should submit a single file named ex4.rkt on ELMS. You may submit many times, but each submission should be one file called ex4.rkt. You may lose points for not following these instructions.
;; Exercise 4 ;; Name: ...your name here...
2 Oveview
The goal of this exercise is to practice using the “design recipe” for systematic problem solving with itemizations and design by composition.
In this exercise, you will develop functions for operating on payroll records for nascent video game company you have founded. There are three kinds of employees in your company:
salaried workers: these employees make a fixed amount annually,
hourly workers: these employees make a fixed hourly rate for some number of hours they work each week,
contract workers: these employees a fixed total amount for jobs that take some number of months to complete.
Each employee has a name and the ability to have a portion of each pay check deducted pre-tax and placed in a retirement savings account.
Your company cuts paychecks on a biweekly basis (every 2 weeks).
We will make the following assumptions:
there are exactly 52 weeks in a year,
everybody pays a tax rate of 17%,
retirement savings are deducted before taxes are computed,
hourly workers get "time and a half" for any hours worked in excess of 40 (meaning they get 1.5 times their usual wage for any hours over 40 they work).
3 Death and Taxes
After much thought, you and your HR department have come up with the following data definition to represent information need to do payroll every 2 weeks:
;; An Employee is a: ;; (make-employee String PayRate Number) ;; Interpretation: an employee has a name, a pay-rate (see below), and ;; a percentage (between 0 and 1) to be deducted for retirement savings (define-struct employee (name pay retire)) ;; A PayRate is one of: ;; - (make-salary Number) ;; - (make-wage Number Number) ;; - (make-contract Number Natural) (define-struct salary (amt)) (define-struct wage (rate hours)) (define-struct contract (total months)) ;; Interpretation: ;; - annual salary in dollars ;; - hourly wage in dollars and weekly number of hours ;; - contract worker making fixed amount over some period of (whole) months ;; Examples: (make-employee "Wile" (make-salary 100000) .07) ;; Wile is a salaried employee, making $100K/year, saving 7% for retirement (make-employee "Bugs" (make-wage 15 40) .01) ;; Bugs is an hourly employee, making $15/hour, saving 1% for retirement (make-employee "Goofy" (make-contract 16000 3) .05) ;; Goofy is a contractor for a $16K job over 3 months, saving 5% for retirement
With these definitions in place, design the following functions. For each design, be sure to complete each step of the design process.
Problem 1: biweekly-gross
Design the function biweekly-gross which computes a given employee’s gross pay for a two week period. (Gross pay means before taxes or retirement savings are deducted.)
Problem 2: biweekly-savings
Design the function biweekly-savings which computes a given employee’s retirement savings for a two week period.
Problem 3: biweekly-tax
Design the function biweekly-tax which computes a given employee’s amount of taxes for a two week period.
Problem 4: biweekly-net
Design the function biweekly-net which computes a given employee’s net pay for a two week period. (Net pay means after taxes and retirement savings are deducted; this is the amount an employee "takes home.")
Problem 5: annual-gross
Design the function annual-gross which computes a given employee’s gross pay for a one year period.