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 course web page, but use of any other source for code is forbidden. If you have problems with the assignment, please see one of the course instructors (rather than any of the teaching assistants or other students).
To start click on this link to download the Test Program 1 starter. Drag the "TestProgram1" folder from your desktop into your "cs101" folder in your "public_html" folder. The "TestProgram1" folder contains three BlueJ projects: NoExit, Illusion, and AcidRain.
Complete each of the following problems, documenting your code well. You are encouraged to reuse the code from your labs or our class examples.
For the first problem, you will draw a FramedRect. The rectangle should be 200 pixels wide and 300 pixels tall. Within this rectangle, you will draw a smaller FilledOval. The oval is a circle with a diameter of 50 pixels. If the user presses the mouse on the circle, s/he can move the circle by dragging it around. One catch, however, is that if the ball hits the wall, it will be dropped by the user. Dragging should only be restarted if the user presses the mouse button on the circle and starts dragging again.
The diagram below is an example of an optical illusion. When you look at it you will probably see gray shadows at the intersections of the lines running between the black squares even though those areas are actually white.
You will also need a class extending FrameWindowController to control interaction with the boxes. The skeleton file we have provided for this is called Illusion. When the program starts, two sets of boxes should be drawn on the screen. The first should start at (1,1), have a box size of 20 and a gap of 4. The other should start at (204,204), have a box size of 30, and a gap of 3.
The Boxes class should also support methods with signatures:
public void showBackground(boolean value)
public boolean contains(Coords point)
When the first method is invoked with a parameter of true, it
should result in showing a red background under the collection of 36
squares generated by the class. That is, it shows a single red
FilledRect which forms a background for the 6 x 6 array of
squares. The background rectangle should enclose all of the squares, but
not extend much beyond them. When the parameter is false, it
should hide the red background.
The second method above returns either true or false depending on whether point is contained in the FilledRect which comprises the background.
Your Illusion class extending FrameWindowController should use these methods so that when a user presses the mouse button down anywhere inside one of the collections of squares, the red background is displayed. When the mouse is released, the red background is hidden again. It does not matter where or whether the mouse is moved in between when it is pressed and released. The behavior is determined only by where it is when the mouse is pressed.
As you may know, the classroom that our course is held in used to be a generic lab, often used for Chemistry labs. Unfortunately, we have just discovered that acid has started dripping from the roof into the room. You are to write a program that simulates this dripping in an attempt to model what happens during this acid rain in the lab. When your program is started it should create an ActiveObject that is an instance of the Roof class. A Roof object will generate circular drops of acid (one every 0.5 seconds) that rain on the window on the computer. Use a random number generator to generate the locations of the acid drops on the window.
When each drop appears, it should have a radius of 3 pixels (and hence a diameter of 6 pixels). Its radius should increase by 1 pixel every 200 milliseconds until the radius is 30 pixels. The increase in size should leave the center of the drop at the same position. That is it increases equally in all directions. When the radius exceeds 30 pixels, the drop should disappear from the screen (it evaporates!). The program should run until the user quits the applet.
This extended version will only be worth a maximum of 4 points of extra credit, so only do this if you are certain that the other programs are done perfectly (especially the style issues).
We will grade your assignment both by running your program over the web and by reading a printout of your Java source code. This Test Program is due by the beginning of your lecture section.
Before submitting your work, make sure that each of the .java files includes a comment containing your name and lab section. Also, before turning in your work, be sure to double check both its logical organization and your style of presentation. Make your code as clear as possible and include appropriate comments describing major sections of code and declarations. Make sure your indentation is all consistent. Refer to the lab style sheet for more information about style.
Print out a copy of your java source files and the Test Program 1 Cover Page. Turn in one stapled hardcopy of all your work, with this cover page on top. There are no assigned exercises from the textbook to be turned in with this Test Program.
We have provided HTML files so that your programs may be run from a browser. As with weekly labs, modify these to include your name. The three files are named "NoExit.html", "Illusion.html", and "AcidRain.html". Drag each of these files to the TextWrangler icon in the dock. Replace the text that reads My_Name with your first and last names, and then save the file.
You can see what the instructors will see by visiting http://bj.middlebury.edu/~USERNAME/cs101/TestProgram1/ from your web browser, where USERNAME is replaced by your username. Click on each of the folder names to visit the applets. You will notice when you do this that a blank "panel" window gets created. Don't worry about this; just close the window to see your program running in the browser.
| 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) | |
| No Exit | |
| 4 pts. | Drawing the screen initially |
| 4 pts. | Dragging |
| 4 pts. | Not allowing the ball to leave the rectangle |
| 4 pts. | Ending the drag when the ball touches the rectangle |
| Optical illusion | |
| 4 pts. | Drawing a grid |
| 4 pts. | Drawing 2nd grid with different dimensions |
| 4 pts. | Showing red background on press |
| 4 pts. | Hiding red background on release |
| Acid rain | |
| 4 pts. | Growing a drop |
| 4 pts. | Having drop disappear at right time |
| 4 pts. | Use of randomization |
| 4 pts. | Continuous creation of drops |
| Miscellaneous (4 pts total) | |
| Extra Credit (4 pts maximum) | |
Good luck and have fun!
Back to Computer
Science 101 Home
Department of Computer
Science