Fall 2001
Homework #5
due WEDNESDAY 7 November 2001
(though this WILL be on Midterm #2)

last updated: Sat Oct 27 23:30:20 EDT 2001

goal... The goal of this assignment is to practice writing an applet and using graphics.

1. create... a simple applet that is a modification of the snowman applet we did in class. Your applet should be 400 pixels wide and 200 pixels high. Your applet should be white, with a black rectangular border, 10 pixels thick. Aha! It looks like a soccer field.

All of your applet code should be inside one file, called hw5<yourCUNIXusername>.java, e.g., hw5eis2003.java.

2. write... a method called drawBall() which draws a ball (i.e., a circle) inside the soccer field. It takes as arguments the x and y coordinates of the CENTER of the ball. The diameter of the ball should be 10 pixels. You can be creative about the color/design of the ball. (Hint: the method might need more than two arguments.)

3. write... a method called drawRobot() which draws a robot inside the soccer field. It takes as arguments the x and y coordinates of the ORIGIN of the robot, where the origin is the upper left corner of the robot. The method should also take a Color argument, specifying the color of the robot. (Hint: the method might need more than three arguments.)

Be creative!!! The shape of the robot can be anything you want. It should fit within a 30x20 pixel bounding rectangle. It can be more than one color, but it should have some identifying portion that is the color you've passed to the drawRobot() method, so that (e.g.) you can call this method for drawing robots from different teams (i.e., distinguished by being different colors).

4. paint... the ball in the center of the field. And paint two robots, one green and one magenta, at their starting positions --- locations (50,90) and (320,90) in the field. Use the draw methods you've written in steps 2 and 3.

here's an (uncreative!) example...

5. comment your code... Your program MUST contain meaningful comments describing each method clearly and concisely. Each file must contain a header comment. Each method must contain a comment at the top (as shown above, elaborating where necessary).

6. create... an html file, called hw5<yourCUNIXusername>.html, which invokes your class file (i.e., hw5<yourCUNIXusername>.class). If you have XWin32 installed, you should be able to see your applet using the appletviewer, as we've done in class. If you don't have XWin32 installed, you should also be able to see your applet using a browser (by loading your html file). See the FAQ page for details.

7. submit... As usual, submit your program in two ways: electronically and hard copy.
You will submit one java file: hw5<yourCUNIXusername>.java
and one html file: hw5<yourCUNIXusername>.html.
To submit both files, make sure that both files are located in the working directory where you invoke the submit script. The submit script should automatically pick up both files (and should tell you so when asking for you to confirm the submission).
The hardcopy should contain 3 sections in the following order: (1) the homework template page, (2) hw4<yourCUNIXusername>.java, and (3) hw4<yourCUNIXusername>.html. You can hand in your hardcopy either by dropping it in a box in the CS department office (Mudd 450) or bringing it to class on Thu Nov 8.

Homeworks must be submitted electronically by midnight on Wed Nov 7; otherwise they will be counted as late (unless you have an approved extension).

Note that this is a relatively simple homework, and the material contained herein WILL be on the midterm (Nov 1). So I highly recommend that you do this homework before the midterm.