Blob


1 ;; The first three lines of this file were inserted by DrScheme. They record metadata
2 ;; about the language level of this file in a form that our tools can easily process.
3 #reader(lib "htdp-advanced-reader.ss" "lang")((modname |37.4|) (read-case-sensitive #t) (teachpacks ((lib "guess-gui.ss" "teachpack" "htdp") (lib "guess.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #t #t none #f ((lib "guess-gui.ss" "teachpack" "htdp") (lib "guess.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp")))))
4 ;;Model
6 ;;State Variables
8 ;;queue : (listof strings)
9 ;;Lists all the tasks which need to be done.
11 (define queue empty)
13 ;;queue-index : N
14 ;;The current index of the queue.
16 (define queue-index 0)
18 ;enter : string -> void
19 ;Adds atask to the end of queue.
21 (define (enter atask)
22 (set! queue (append queue
23 (list atask))))
25 ;next : -> string
26 ;Returns the next task in the queue based on queue-index. If the end of the queue is reached, return the current task in the queue specified by queue-index. If the queue is empty, return 'NoneLeft.
28 (define (next)
29 (cond
30 [(empty? queue) 'NoneLeft]
31 [(= (length queue) (add1 queue-index)) (list-ref queue queue-index)]
32 [else (begin (set! queue-index (add1 queue-index))
33 (list-ref queue queue-index))]))
35 ;remove : -> void
36 ;Removes the first task in the queue. If there are no tasks left to be removed, do nothing.
38 (define (remove)
39 (cond
40 [(empty? queue) (void)]
41 [else (set! queue (rest queue))]))
43 ;count : -> N
44 ;Counts the number of items in the queue.
46 (define (count)
47 (length queue))
49 ;;View
51 ;;GUI-items, text and messages
52 (define task-message (make-message "Welcome to the Task Manager"))
53 (define task-number-message (make-message "2000"))
54 (define input-text (make-text "Task: "))
56 ;;Controller
58 (define (enter-callback event)
59 (cond
60 [(equal? (text-contents input-text) "") true]
61 [else (begin (enter (text-contents input-text))
62 (draw-queue-number)
63 (cond
64 [(= (length queue) 1) (draw-first-task)]
65 [else true]))]))
67 ;;draw-queue-number : -> true
68 ;;Draws the queue number and returns true.
69 (define (draw-queue-number)
70 (draw-message task-number-message (number->string (length queue))))
72 ;draw-first-task : -> true
73 ;Draws the first task in the queue and returns true.
74 (define (draw-first-task)
75 (draw-message task-message (first queue)))
77 (define (next-callback event)
78 (cond
79 [(>= (length queue) 2)
80 (begin (remove)
81 (draw-queue-number)
82 (draw-first-task))]
83 [(= (length queue) 1)
84 (begin
85 (remove)
86 (draw-queue-number)
87 (draw-message task-message "No more tasks left!"))]
88 [(= (length queue) 0) true]))
90 (define (quit-callback event)
91 (hide-window task-manager-win))
93 (define enter-button (make-button "Enter" enter-callback))
94 (define next-button (make-button "Next" next-callback))
95 (define quit-button (make-button "Quit" quit-callback))
97 (define task-manager-win
98 (create-window (list (list task-message task-number-message)
99 (list input-text enter-button)
100 (list next-button quit-button))))
102 ;;Tests
103 #|
104 (begin (enter "hi")
105 (enter "joe")
106 (enter "it's")
107 (enter "me")
108 (and (equal? (list "hi" "joe" "it's" "me") queue)
109 (begin (next)
110 (equal? (next) "it's")
111 (remove)
112 (and (= 3 (count))
113 (equal? queue (list "joe" "it's" "me"))))))
114 |#
116 ;;Wish-list
118 ;;Initialize queue, queue-index