hw7 - AC 2C 3C 4C 5C 6C 7C 8C 9C 10C JC QC KC)) (define...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
;; #1) (define-class (random-generator x) (instance-vars (nmbr 0) (cnt 0)) (method number (begin (set! cnt (+ 1 cnt)) (set! nmbr (random x)) nmbr)) (method count cnt)) ( ;; #2) (define-class (coke-machine max cost) ( (instance-vars (cokes 0) (money 0)) (method (fill a) (set! cokes (+ cokes a))) (method (deposit b) (set! money (+ b money))) (method coke (cond ((> cost money) '(NOT ENOUGH MONEY)) ((> cokes max) '(NOT ENOUGH ROOM)) ((= cokes 0) '(MACHINE EMPTY)) (else (begin (set! money (- money cost)) (set! cokes (- cokes 1)) money))))) m ;; #3) (define ordered-deck '(AH 2H 3H 4H 5H 6H 7H 8H 9H 10H JH QH KH AS 2S 3S 4S 5S 6S 7S 8S 9S 10S JS QS KS AD 2D 3D 4D 5D 6D 7D 8D 9D 10D JD QD KD
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: AC 2C 3C 4C 5C 6C 7C 8C 9C 10C JC QC KC)) (define (shuffle deck) (if (null? deck) '() (let((Card (nth (random (length deck)) deck))) (cons card (shuffle (remove card deck))) ))) (define-class deck (instance-vars (countcards 52) (cards (shuffle ordered-deck)) (dealt 0)) (method empty? (if (= countcards 0) '#t '#f)) (method deal (cond ((= countcards 0) '()) (else (begin (set! countcards (- countcards 1)) (set! dealt (car cards)) (set! cards (cdr cards)) dealt))))) d ;; #4) (define-class (miss-manners x) (method (please message parameter) (ask 'x 'message parameter)))...
View Full Document

Ask a homework question - tutors are online