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, and our on-line examples and web pages, but use of any other source for code is forbidden. You may not discuss these problems with anyone aside from the course instructors. You may only ask the TAs for help with hardware problems or difficulties in retrieving your program from a disk or network.
Complete each of the following problems, documenting your code well. You are encouraged to reuse the code from your labs or our class examples. Submit your code in the usual way by dragging it into the Dropoff folder. Please do not submit three separate folders. Instead, place the folders for all three of your complete programs into one folder, make sure that your name appears in the title of the main folder and each of the subfolders, and then place the main folder in our dropoff folder.
Your mission, should you choose to accept it, is to write a program to let Indiana Jones practice going through the "Tunnel of Death"! The two red rectangles on the screen represent fiery hot volcanic rocks. One touch of them will kill Indy instantly!
Your program should allow the user to drag an image of Indy through the narrow (30 pixel wide) tunnel between the two hot rectangles. If he touches the side (dying instantly), then we will let the user resuscitate him by clicking anywhere on the window. This will move him back to his original starting spot (sound familiar?) so that he can try again.
If Indy should get completely through the tunnel (i.e., even his toes are above the fiery rock) then you should display a message indicating that he has succeeded. If he dies, you should display a message to that effect as well.
By the way, Indy is allowed to rest along the way - there is no penalty if the user stops dragging him before he gets all the way to the top. As long as he has not died, the user can simply grab him and start dragging again.
You can create the image of Indy on the screen from the file indiana_jones.jpg, resetting it to have width 18 and height 30 to provide the appropriate level of difficulty in getting him through the tunnel.
A demo version should appear below if your web browser supports Java.
For this problem we would like you to write a class representing a counter which keeps track of the number of times that the mouse has been pressed on it. To make it a bit more interesting, we would also like it to be draggable and to have a small red reset button associated with it.
A running version of the program we hope you produce is provided below (if your browser handles applets correctly):
If the user presses the mouse on the red button on the left side of the counter, then the counter should be reset to 0. If the user presses the mouse anywhere else on the counter, then the count should be increased by one. If the user then drags the counter, it should move along with the mouse as usual. Pressing the mouse anywhere else in the window should have no effect. (Pressing on the red reset button followed by a drag should NOT result in the counter being moved.)
You are to write the DraggingCounter class as well as a CounterMover class extending WindowController that will be responsible for creating and manipulating the counter as in the demo. Please make sure that your program behaves exactly like the one in the demo. The start-up folder includes some constants that will help you figure out the relative sizes and locations of the components of the counter. The DraggingCounter will have methods move(dx,dy), contains(pt), increment(), inResetButton(pt), and reset(). The next to last method determines if pt is inside the reset button, while the last resets the counter to 0.
This test program allows the user to drag and drop balls which bounce once on the bottom of the screen and then rise until they disappear off the top of the screen.
When the user first presses the mouse button a ball appears that is centered around the mouse location. The ball should have a radius between 10 and 20 (inclusive), chosen randomly. If the user presses and drags the mouse, the ball should appear and move around as usual.
When the user releases the mouse button, the ball should drop to the ground at a randomly chosen speed. It should bounce at the bottom of the screen and leave a mark (a FilledOval) on the ground. The ball should then rise until it disappears off the top of the screen.
A running version of the program should be visible below if your browser handles applets correctly:
Value | Feature |
Style (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 |
2 pts. | Parameters used appropriately |
Correctness (16 pts for each of 3 programs) | |
Tunnel | |
Drawing the screen initially | |
Dragging "Indy" | |
Dying when he touches a rock | |
Winning when get above the top | |
Messages displayed correctly | |
Dragging Counter | |
Drawing the counter on the screen properly | |
Reset button works appropriately | |
Counter incremented appropriately | |
Dragging functions correctly | |
Bouncing Ball | |
Creating ball when clicked | |
Dragging ball before released | |
Ball bounces appropriately | |
Ball leaves mark on the floor | |
Miscellaneous (4 pts total) | |
Extra Credit (4 pts maximum) | |