Week 3 Set a
Due Date Mon at 9pm (Week 3)
Purpose It is time to graduate from programming to program design.
Finger Exercises
Exercise 1 Design amount-of-ticket. Given the speed of a car and the speed limit of some road, the function determines the penalty a driver has to pay. Here is the table printed on the back of such speeding tickets:
Percentage of Excess Speed
Amount ($)
up to 10
50
up to 50
250
up to 100
500
beyond
2000
Hint Create a wish list, because you will need auxiliary functions.
Exercise 2 Design the world program control. Its task is to move a red dot—
as in (circle 3 "solid" "red")— on a 200-by-200 canvas in response to the left and right arrow keys. Every time the user presses the left arrow key, the dot moves left by 5 pixels; when the user presses the right arrow key, the dot moves right by 8 pixels. The dot does not respond to any other keyboard input. The main function consumes the initial x coordinate of the dot.
Graded Exercises
Exercise 3 Design the world program stacked. The program manages a one-line text editor of 600 by 50 pixels. Every time the user presses an alphanumeric key, the program adds this letter or digit to the front of the existing text. When the word gets too long, letters must drop off the right end.
The main function consumes the initial text in the buffer.
Hint Take a look at place-image/align.