-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRacketDesign1
45 lines (23 loc) · 5.63 KB
/
RacketDesign1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
CS1101 Design1
; Design homework 1 (define WPI_ID1 "ajli") ; the text that comes before the @ in your wpi email (define WPI_ID2 "mzheng"); fill in if working with a partner; leave as "" if working alone.
;; ; Changes made: - Computation 1 all HtDF: The tests in Step 2 are sufficient and therefore no need for extra tests in step 5. ; - Computation 2 all HtDF: The tests in Step 2 are sufficient and therefore no need for extra tests in step 5.
; ; Part 1 ; ;; The problem domain is: sea travel ; ;; The category of things is: boats ; ;; The three sorts of are: yacht, speedboat, sailboat ; ;; All three have the properties : can charter, know the location, has a captain ; ;; Yacht have the unique property: luxurious ; ;; Speedboat have the unique property: very fast ; ;; Sailboat have the unique property: eco friendly, comfy ; ; ;; The types of computations we will do are: ; ;; 1) find the location of a boat ; ; ;; 2) Determine which boat is most suitable for you ; ;; Yacht: luxurious, increases comfort, not eco feiendly ; ;; Speedboat: very fast, decreases comfort, not eco friendly ; ;; Sailboat: No fuel, increases comfort, eco friendly ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;Part 2
(define-struct yacht (captain location)) ;; a yacht is a (make-yacht captain string) ;interp. ;; The captain is the borowwer of the boat ;; Location is the place where the Yacht is docked ; ;; template: ; (define (yacht-fcn a-yacht) ; (... ; (yacht-captain a-yacht) ; (yacht-location a-yacht) ; )
;; examples: (define DONALD-YACHT (make-yacht "Trump, Donald" "Monaco")) (define JIANG-YACHT (make-yacht "Li, Jiang" "Shanghai"))
(define-struct speedboat (captain location)) ;; a speedboat is a (make-speedboat captain string) ;interp. ;; The captain is the borowwer of the boat ;; Location is the place where the speedboat is docked ; ;; template: ; (define (speedboat-fcn a-speedboat) ; (... ; (speedboat-captain a-speedboat) ; (speedboat-location a-speedboat) ; )
;; examples: (define KYLE-SPEEDBOAT (make-speedboat "Crash, Kyle" "Miami")) (define KAREN-SPEEDBOAT (make-speedboat "Manager, Karen" "Tampa"))
(define-struct sailboat (captain location)) ;; a sailboat is a (make-sailboat captain string) ;interp. ;; The captain is the borowwer of the boat ;; Location is the place where the sailboat is docked ; ;; template: ; (define (sailboat-fcn a-sailboat) ; (... ; (sailboat-captain a-sailboat) ; (sailboat-location a-sailboat) ; )
;; examples: (define BRUCE-SAILBOAT (make-sailboat "Miller, Bruce P." "Bahamas")) (define CHARLES-SAILBOAT (make-sailboat "Smith, Charles" "Australia"))
;; [TODO: Itemization Data Definition] ;; A Boat is the following: ;; -Yacht ;; -Speedboat ;; -Sailboat ;; interp. The three sorts of boats which our clients can borrow with info ;; about the boats
; ;; template: ; (define (boat-fcn a-boat) ; (cond ; [(Yacht? a-boat) (yacht-fcn a-boat)] ; [(Speedboat? a-boat) (speedboat-fcn a-boat)] ; [(Sailboat? a-boat) (sailboat-fcn a-boat)] ; ) ; )
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; Part 3
; Computation #1) ; ;; Step 1 - Signature, Purpose, Stub ; ;; Boat -> String ; ;; Purpose: consumes a boat then produces the location of that boat ; ;; stub: ; ;;(define (locate a-boat) "UK")
;; Step 2 - Examples(Tests) (check-expect (locate DONALD-YACHT) "Monaco") (check-expect (locate JIANG-YACHT) "Shanghai") (check-expect (locate KYLE-SPEEDBOAT) "Miami") (check-expect (locate CHARLES-SAILBOAT) "Australia") (check-expect (locate BRUCE-SAILBOAT) "Bahamas")
; ;; Step 3 - Template and Inventory ; ;; template: ; ;(define (locate a-boat) ; ; (cond ; ; [(Yacht? a-boat) (yacht-fcn a-boat)] ; ; [(Speedboat? a-boat) (speedboat-fcn a-boat)] ; ; [(Sailboat? a-boat) (sailboat-fcn a-boat)])) ; ;inventory: I have selectors for each sort of boat, find boat location ;
;; Step 4 - Function Body (define (locate a-boat) (cond [(yacht? a-boat) (yacht-location a-boat)] [(speedboat? a-boat) (speedboat-location a-boat)] [(sailboat? a-boat) (sailboat-location a-boat)] ) )
; Computation #2) ; ;; Step 1 - Signature, Purpose, Stub ; ;string->string ; ; ; Purpose: consumes an adjective corresponding to each boat. Luxurious corresponds to yacht, ; ;fast corresponds to speedboat, comfy corresponds to sailboat, eco friendly corresponds to sailboat, ; ;price corresponds to "It depends on your personal preferences and priorities ; ; ;Stub (define (suitable-boat criteria) "price")
;; Step 2 - Examples(Tests): (check-expect (suitable-boat "luxurious") "yacht") (check-expect (suitable-boat "fast") "speedboat") (check-expect (suitable-boat "comfy") "sailboat") (check-expect (suitable-boat "eco friendly") "sailboat") (check-expect (suitable-boat "price") "Sorry, our boat rental company cannot assist you at this time, please try other services.")
; ;; Step 3 - Template and Inventory ; ;; template: ; ;(define (suitable-boat criteria) ; ; (cond ; ; [(equal? criteria "CRITERIA_1") "yacht"] ; ; [(equal? criteria "CRITERIA_2") "speedboat"] ; ; [(equal? criteria "CRITERIA_3") "sailboat"] ; ; [(equal? criteria "CRITERIA_4") "sailboat"] ; ; [else "It depends on your personal preferences and priorities"])) ; ; ;inventory: I have selectors for each sort of boat, outputs boat based on preference ;
;; Step 4 - Function Body (define (suitable-boat criteria) (cond [(equal? criteria "luxurious") "yacht"] [(equal? criteria "fast") "speedboat"] [(equal? criteria "comfy") "sailboat"] [(equal? criteria "eco friendly") "sailboat"] [else "Sorry, our boat rental company cannot assist you at this time, please try other services."] ) )