CPSC 120 -- Assignment #2: Stay on Target
Due Friday, October 10, 2008 by 4 p.m.

Write a program that simulates an arrow hitting a target. Begin by creating a class that extends JFrame with the appropriate methods to create and display a window. For this assignment the drawing does not need to scale with the window. In order to prevent users from resizing the window you can put the statement frame.setResizable(false) after the statement that sets the frame size and before the statement that sets the frame to visible in the main method. The window should contain a drawing of an archery target, five concentric circles of alternating colors. Each circle should be labeled with the points received for hitting the ring, 2 through 10 in increments of 2. After Drawing the target draw where a random arrows hits the target by drawing an X. This will require generating random numbers for the x and y coordinates of the arrow's location in the window. The random x and y coordinates should not exceed the window dimensions. Use the Graphics method drawLine to draw the X such that the two lines of the X intersect at the x and y coordinates of the arrow. Finally, calculate the the score of an arrow that hits the target where the X is. To calculate the score you must find the distance from the the center of the target to the center of the X. You can calculate this using the Pythagorean theorem with Cartesian coordinates, √((x2-x1)2+(y2-y1)2). Display the score with some text in the window, but outside the target. An example of what your application should look like is below.

Other Requirements

As usual, use good programming techniques. You should use good variable names, constants where appropriate, whitespace, and correct indentation and alignment of statements. Documentation must include a comment for the class (it should include the @author tag and a clear, complete description of what the program does) and comments for the main and paint methods. The program should be broken up into logical sections and each section should be documented with a brief description of what it does. Your program must be in the package assign2.

Your program must compile!!! A program with a compilation error, no matter how small, will receive at most 25% credit. Your program must compile and run.

Academic Integrity Reminder!!! Programming assignments are to be your own work. You may get help on the specifics of the assignment from no one except the instructor. You may not show your program to anyone or look at anyone else's program or share ideas with anyone about how to write the program or solve the problem.

Hand In

Turn in a printed copy of your program (the source code) and email the java file to your instructor. Be sure the subject line says cpsc120 assign2.