;; Object Oriented Programming Style in Scheme (define (make-account password balance) (lambda (op) (let ((passwd (begin (display "Enter Password") (newline) (read)))) (cond ((not (eq? password passwd)) (display "Incorrect Password") (newline)) (else (cond ((eq? op 'balance) (display "Balance is ") (display balance) (newline)) ((eq? op 'withdraw) (let ((amount (begin (display "Enter Amount") (newline) (read)))) (cond ((<= amount balance) (set! balance (- balance amount)) 'done) (else (display "Amount exceeds balance") (newline))))) ((eq? op 'deposit) (let ((amount (begin (display "Enter Amount") (newline) (read)))) (set! balance (+ balance amount)) 'done)) (else (display "Incorrect Operation") (newline)) ))) ))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;; Sample Session ==> (define account (make-account 'ben 1000)) ACCOUNT ==> (account 'balance) Enter Password ben Balance is 1000 #T ==> (account 'withdraw) Enter Password ben Enter Amount 1500 Amount exceeds balance #T ==> (account 'withdraw) Enter Password ben Enter Amount 140 DONE ==> (account 'balance) Enter Password ben Balance is 860 #T ==> (account 'deposit) Enter Password ben Enter Amount 400 DONE ==> (account 'balance) Enter Password ben Balance is 1260 #T ==> (account 'balance) Enter Password foo Incorrect Password #T