Please send questions to st10@humboldt.edu .

(define MAX 40)
(cond
  [(> MAX 50) "look"]
  [(> MAX 30) "view"]
  [(> MAX 20) "see"]
  [else "notice"]
)

; contract: owner?: string -> boolean
; purpose: expects a person's name, and produces 
;          whether or not that person is one
;          of the owners, Carlos, Sandra, or George

;(define (owner? a-name)
;  ...
;)

(check-expect (owner? "Carlos") true)
(check-expect (owner? "Sandra") true)
(check-expect (owner? "George") true)
(check-expect (owner? "Fred") false)

; the result of the TEMPLATE design-recipe step:

;(define (owner? a-name)
;  (cond
;    [... ...]
;    [... ...]
;    [... ...]
;    [else ...]
;  )
;)

;(define (owner? a-name)
;  (cond
;    [(equal? "Carlos" a-name) true]
;    [(equal? "Sandra" a-name) true]
;    [(equal? "George" a-name) true]
;    [else false]
;  )
;)

; refactoring: is when you improve working code

; when you see that 3 cases above have the SAME result-expression,
;    you MIGHT decide to refactor -- here, to combine those
;    three true cases into one case;

;(define (owner? a-name)
;  (cond
;    [(or (equal? "Carlos" a-name)
;         (equal? "Sandra" a-name)
;         (equal? "George" a-name)) true]
;    [else false]
;  )
;)

; for boolean functions, you can often end up with a
;    body that is just a boolean expression, true if
;    function's result is true...

(define (owner? a-name)
   (or (equal? "Carlos" a-name)
       (equal? "Sandra" a-name)
       (equal? "George" a-name))
)

; contract: get-greeting: string -> string
; purpose: expects a person's name, and if it is
;          the name of an owner, it produces a
;          personalized informal greeting; otherwise,
;          it produces a personalized formal greeting

;(define (get-greeting a-name)
;  ...
;)

; I decide I'd like a boolean function to tell if
;    a name is that of an owner -- I went BEFORE get-greeting
;    to develop that...

; how many specific examples/tests here?
; BECAUSE I have such a well-tested auxiliary function
;   for seeing if someone is an owner -- I MIGHT decide 
;   that 2 test cases are enough for get-greeting.
;   Or I might do all 4... (don't skimp to 2 WITHOUT
;   a well-tested auxiliary being involved!!)

(check-expect (get-greeting "George")
              "Hiya, George!")
(check-expect (get-greeting "Sandra")
              "Hiya, Sandra!")
(check-expect (get-greeting "Carlos")
              "Hiya, Carlos!")
(check-expect (get-greeting "Fred")
              "Welcome to Toppers, Fred -- may someone help you?")

(define (get-greeting a-name)
  (cond
    [(owner? a-name) (string-append "Hiya, " a-name "!")]
    [else (string-append "Welcome to Toppers, " a-name
                         " -- may someone help you?")]
  )
)

(get-greeting "Carlos")
(get-greeting "Thomas")

; say that we'd like a function that expects a number grade
;    and produces the corresponding letter grade for that
;    number grade

; maybe we'd better clarify (perhaps part of our
; problem analysis and data definition?) the
; definitions, if you will, for each grade letter;

; say we mean grades that are typically between 0 and 100...

; we might decide that a grade is an A if in [90, infinity)
; and a B is in [80, 90)
; and a C is in [70, 80)
; and a D is in [60, 70)
; and an F is in (-infinity, 60)

; contract: get-letter-grade: number -> string
; purpose: expects a numeric grade, and produces the
;          appopriate letter grade based on the following
;          grading scale:
;          letter grade           numeric grade in interval
;            A                    [90, infinity)
;            B                    [80, 90)
;            C                    [70, 80)
;            D                    [60, 70)
;            F                    (-infinity, 60)

;(define (get-letter-grade grade-num)
;  ...
;)

; oy, -- 5 different letter grade cases to test,
;    PLUS 4 boundaries between them -- need at least 9
;    tests!

(check-expect (get-letter-grade -24) "F")
(check-expect (get-letter-grade 60) "D")
(check-expect (get-letter-grade 62) "D")
(check-expect (get-letter-grade 70) "C")
(check-expect (get-letter-grade 76) "C")
(check-expect (get-letter-grade 80) "B")
(check-expect (get-letter-grade 85.5) "B")
(check-expect (get-letter-grade 90) "A")
(check-expect (get-letter-grade 100) "A")

; this is the result of my template step 

;(define (get-letter-grade grade-num)
;  (cond
;    [... ...]
;    [... ...]
;    [... ...]
;    [... ...]
;    [else ...]
;  )
;)


(define A-MIN 90)
(define B-MIN 80)
(define C-MIN 70)
(define D-MIN 60)

(define (get-letter-grade grade-num)
  (cond
    [(>= grade-num A-MIN) "A"]
    [(>= grade-num B-MIN) "B"]
    [(>= grade-num C-MIN) "C"]
    [(>= grade-num D-MIN) "D"]
    [else "F"]
  )
)

; a function for an automated answering system, that
; produces the appropriate greeting for a phone digit
; pressed

; contract: phone-greeting: number -> string
; purpose: expects a phone digit press, and produces
;          the appropriate greeting for that choice:
;          option       greeting
;          1            Welcome to the Help Desk
;          2            Welcome to the Library
;          3            Welcome to the Depot
;         anything else Please wait for a real human operator

;(define (phone-greeting option)
;  ...
;)

; at LEAST 4 specific examples/tests -- 1, 2, 3, any other digit

(check-expect (phone-greeting 1) "Welcome to the Help Desk")
(check-expect (phone-greeting 2) "Welcome to the Library")
(check-expect (phone-greeting 3) "Welcome to the Depot")
(check-expect (phone-greeting 4) 
              "Please wait for a real human operator")

; result of template step, since I have 4 cases...

;(define (phone-greeting option)
;  (cond
;    [... ...]
;    [... ...]
;    [... ...]
;    [else ...]
;  )
;)

(define (phone-greeting option)
  (cond
    [(= 1 option) "Welcome to the Help Desk"]
    [(= 2 option) "Welcome to the Library"]
    [(= 3 option) "Welcome to the Depot"]
    [else "Please wait for a real human operator"]
  )
)

(phone-greeting 2)
(phone-greeting 9)