CS 51 Test Program #1
Due: Friday, October 19, 2007 at 4 PM

This document describes what you are to do to complete your first test program. A test program is a laboratory that you complete on your own, without the help of others. It is a form of take-home exam. You may consult your text, your notes, your lab work, or our on-line examples and web pages, but use of any other source for code is forbidden. If you have problems with the assignment, the only person you may talk to is me, and I will give limited assistance.

You will find demos and starter files for these questions in the tp1 folder in the labs folder of CS051 on the server. Complete each of the following problems, documenting your code well. You are encouraged to reuse the code from your labs or our class examples. Place the folders for your three problems in a larger folder whose name includes your name and tp1. Submit that folder in the usual way by dragging it into the dropbox folder.

Problem 1: A new broom sweeps clean

For the first problem, you are to write a program that emulates a broom that can sweep a rectangle around the screen. The broom will be represented by a small ball with diameter 10 that appears when the mouse is pressed and disappears when the mouse is released. While the mouse is depressed, the ball is dragged along by the mouse (the upperleft corner of the ball is always at the mouse location). There is also a filled square (30 pixels to a side) showing on the screen. If the broom bumps into the square during a drag, then the square will move the same distance (and in the same direction) as the broom, as indeed it would if you had a real broom.

Notice that we are asking you to have the broom push the square, not just drag it. Thus if the mouse is depressed when it is not over the square, but then is dragged over the square, the square should be pushed ahead of the mouse (that is, after the drag, the mouse will still not be on top of the square). Of course if the mouse is depressed on top of the square, then the broom will drag the square, but this program should also be able to push (and the code to do the pushing will automatically do that dragging). Please use the method overlap to determine if the broom has been moved over the square.

One warning: If you are pushing the square diagonally, the square will have a tendency to slide off of the broom. This is because movements parallel to the side of the square will not affect the square (and the computer is so fast that some of your diagonal moves will end up parallel to the square). This is a "feature" not a "bug" (this is what happens with real brooms), so don't worry about it as long as the square generally is moved along with the broom.

Problem 2: Playing with windows

For this program you are to create a class to represent a window on a computer screen. The diagram below shows what such a window should look like (except that your window should have a title with your name replacing "Kim").

As you can see, the window has a title bar (including title), an outline, a "go-away circle", and a resize box. The title bar should be 14 pixels high and extend across the entire top of the window, the "go-away circle" should have diameter 7 pixels while the resize box should be about 10 pixels square and should occur in the lower right corner of the window.

Like most computer windows, windows from your class can be dragged by grabbing them on the title bar and dragging. They can also be resized by grabbing the small square in the lower right hand corner and dragging that around. The window is closed if the user clicks on the "go-away circle".

We have supplied you with a class, WindowManager, extending WindowController, that creates a window on the screen and then determines whether the window should be dragged or resized (or indeed do nothing at all) in response to user actions, and sends appropriate messages to the window.

You are to write a class Window that can be used with class WindowManager and that has the appropriate behavior. As well as the constructor, the class should support methods

You should not modify the WindowManager class in any way to accomplish the required parts of this program. Feel free to add other graphic items to the Window class to make it look more attractive.

Problem 3: Skyscape

The last program is an homage to James Turrell and his skyscape sculpture in the courtyard between Edmunds and Lincoln. You are to implement a program that draws a picture simulating the view that you would see if you were floating on your back in the pool while looking up at the sky. To make it interesting, every time the user clicks in the window, a cloud should be created at that spot and then slowly float from left to right across the sky. Because the cloud is above the roof of the skyscape, it will be obscured when it is behind it.

To make it clear that this is an homage, please have the program place the text "Turrell" (in blue) on the right edge of the screen each time a cloud passes out of the window. The y-coordinate of the text item should be the same as the middle of the cloud that has disappeared.

To complete the program, you will need to write two classes: a Skyscape class that extends WindowController and a FloatingCloud class that extends ActiveObject. The Skyscape class is responsible for drawing the roof of the skyscape and creating a new cloud each time the mouse is clicked, while the FloatingCloud class represents the cloud images that float from left to right across the screen.

The window is 600 pixels wide and 600 pixels high. The roof should be 400 by 400, while the interior is 200 by 200. Hint: The roof is actually composed of 4 rectangles as the blue sky needs to be behind the roof. I suggest that you first get it to work without drawing the blue sky and only add the sky after everything else is already working.

Grading Point Allocations

Value Feature
Code Quality (16 pts for each of 3 programs)
2 pts. use of boolean conditions
2 pts. ifs/whiles
2 pts. appropriate vble (instance/local, public/private)
2 pts. Descriptive comments
2 pts. Good names
2 pts. Good use of constants
2 pts. Appropriate formatting (indenting, white space, etc.
2 pts. Parameters used appropriately
Correctness (16 pts for each of 3 programs)
4 pts. Drawing the screen initially
4 pts. Dragging the broom
4 pts. Pushing the "dirt"
4 pts. Showing/hiding the broom
4 pts. Drawing a window
3 pts. Moving the window
3 pts. Resizing the window
3 pts. Making the window go away
3 pts. Centering title at all sizes
3 pts. Initial screen drawn correctly
3 pts. Cloud created at click location
3 pts. Cloud floats correctly from left to right
3 pts. Cloud floats behind roof correctly
4 pts. "Turrell" written at proper location
Miscellaneous (4 pts total)
Extra Credit (4 pts maximum)