;; The first three lines of this file were inserted by DrRacket. They record metadata
;; about the language level of this file in a form that our tools can easily process.
#reader(lib "htdp-beginner-reader.ss" "lang")((modname 15.4.1) (read-case-sensitive #t) (teachpacks ()) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ())))
; Exercise 15.4.1
; bank-interest : number(balance) -> number
; assumes balance is at least 0
; bank-interest-rate : number -> number
"Examples of bank-interest-rate:"
(check-expect (bank-interest-rate 200) 0)
(check-expect (bank-interest-rate 500) 0.01)
(check-expect (bank-interest-rate 800) 0.01)
(check-expect (bank-interest-rate 1000) 0.02)
(check-expect (bank-interest-rate 2500) 0.02)
(check-expect (bank-interest-rate 4000) 0.03)
(check-expect (bank-interest-rate 5000) 0.03)
(define (bank-interest-rate balance)
; balance a number in dollars
(cond [(< balance 500) .00]
[ (and(>= balance 500)
(< balance 1000)) .01]
[ (and(>= balance 1000)
(< balance 4000)) .02]
[(>= balance 4000) .03]
))
(check-expect (bank-interest 200) 0)
(check-expect (bank-interest 500) (* 500 .01)) ; or 5
(check-expect (bank-interest 800) (* 800 .01)) ; or 8
(check-expect (bank-interest 1000) (* 1000 .02)) ; or 20
(check-expect (bank-interest 2500) (* 2500 .02)) ; or 50
(check-expect (bank-interest 4000) (* 4000 .03)) ; or 120
(check-expect (bank-interest 5000) (* 5000 .03)) ; or 150
(define (bank-interest balance)
; balance a number, in dollars
(* balance (bank-interest-rate balance))
)