;; The first three lines of this file were inserted by DrScheme. 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 interest) (read-case-sensitive #t) (teachpacks ()) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ()))) ;; Contract: number -> number ;; Purpose: determine a yearly interest rate based on amount ;; The interest rate is 0.04 for amounts between 0 and ;; 1000 (incl), 0.045 for amounts between 1000 and 5000 (incl), ;; and 0.05 for larger amounts. ;; Examples: (interest-rate 500) -> 0.04 ;; (interest-rate 1000) -> 0.04 ;; (interest-rate 10000) -> 0.05 (define (interest-rate amount) (cond [(< amount 0) 0.0] [(<= amount 1000) .04] [(<= amount 5000) .045] [(> amount 5000) 0.05] ) ) ;; Tests (interest-rate 500) ;; expected value 0.04 (interest-rate 1000) ;; expected value 0.04 (interest-rate 10000) ;; expected value 0.05 (interest-rate -500) ;; expected value 0.0 (interest-rate 3000) ;; expected value 0.045 ;; Write a function that, given an amount of money, ;; computes the interest on that amount that accumulates in a year