;; Problem: We have interns, who work at an hourly rate, and ;; full-time employees, who are salaried. We need to keep track ;; of these employees, and print out their paychecks once a ;; month: "Pay to the order of Matthias Felleisen, $15000." (define-struct intern (name wage/hr hours/wk)) (define-struct fulltime (name salary)) ;; An Employee is one of: ;; - (make-intern String Number Number) ;; - (make-fulltime String Number) ;; interp: ;; A (make-intern n w h) is an intern record where n is the name, ;; w is the hourly wage, and h is the hours worked per week. ;; A (make-fulltime n s) is a fulltime employee record where ;; n is the name and s is the monthly salary. #;(define (emp-template an-emp) (cond [(intern? an-emp) ... (intern-name an-emp) ... (intern-wage/hr an-emp) ... (intern-hours/wk an-emp) ...] [(fulltime? an-emp) ... (fulltime-name an-emp) ... (fulltime-salary an-emp) ...])) ;; monthly-wage : Employee -> Number ;; given an employee, calculate monthly wage (define (monthly-wage emp) (cond [(intern? emp) (* (intern-wage/hr emp) (* 4 (intern-hours/wk emp)))] [(fulltime? emp) (fulltime-salary emp)])) ;; Employee -> String ;; Get the name of the given employee (define (get-emp-name emp) (cond [(intern? emp) (intern-name emp)] [(fulltime? emp) (fulltime-name emp)])) ;; print-paycheck : Employee -> String ;; Given an employee record, produce their monthly paycheck (define (print-paycheck emp) (string-append "Pay to the order of " (get-emp-name emp) ", $" (number->string (monthly-wage emp)) ".")) ;; examples (define e1 (make-intern "Rachel Bakish" 10 20)) (define e2 (make-fulltime "Matthias Felleisen" 15000)) ;; (print-paycheck e1) --> ;; "Pay to the order of Rachel Bakish, $800." ;; (print-paycheck e2) --> ;; "Pay to the order of Matthias Felleisen, $15000." (check-expect (print-paycheck e1) "Pay to the order of Rachel Bakish, $800.") (check-expect (print-paycheck e2) "Pay to the order of Matthias Felleisen, $15000.") ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; A Shape is one of: ;; - "circle" ;; - "square" ;; - 'unknown ;; Note: Shape is an enumeration ;; Template (define (shape-temp s) (cond [(and (string? s) (string=? "circle" s)) ... ] [(and (string? s) (string=? "square" s)) ... ] [(symbol? s) ...])) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; #| Design a program that moves a colored ball back and forth across the canvas. It should not start until the "player" presses a key and it should pause when the "player" presses a key again. |# ;; See stop-and-go code posted on blog