Worth:20 points
Problem Description: The provided applet allows you to select one of two figures and allows you to draw the figure on the applet. Using the mouse select a figure and in the drawing area press the mouse button and drag. A figure should be drawn.
Your requirements for this lab are to use the provided information and add code so that the area, perimeter, center point and top left corner point of the drawn figure are also be displayed.
example4.html using your favorite browser (Firefox, IE, etc.). See this page for
a reminder on makefiles (and some added information).
The following equations are provided for assistance - they are not in proper java syntax and will not work unless you put them in proper Java syntax..
area = (3.14)r^2 3.14 times radius raised to the second power
perimeter = (3.14)(2)r 3.14 times 2 times r
You should use Math.PI instead of 3.14 for a more accurate computation.
You also may be interested in the Math.pow(double a, double b) method.
Some of you may realize that what you are drawing is not really a circle. I have added this page for fun. For the purposes of this lab you can pretend that the figure you are drawing is a circle (i.e., that the width and the height are the same).
center point (x,y) = (top left x + (1/2)width, top left y + (1/2)height)
Test (hand compute) your results to make sure the computations are
correct!!!!!
All the following should be computed and displayed for both the circle and rectangle on the applet for full
credit.
Web Page Submission Required Contents:
area = hw height times width
perimeter=2h+2w 2 times height plus 2 times width
area, perimeter, center point(x,y), top left corner(x,y)
Note you may need to modify the html file and the applet tags height and
width values to
fully display all the information on the applet.
You can (and should) make your numbers look nicer. See the formatting links on the lab index page under lab 4 (particularly here)
Describe how the paint method works.
What do you think the "if" statement is doing in the
paint method?
How does the figure,x,y,width and height variables relate to
the paint method and
where are they being set?
How do the ButtonHandler and MouseHandler classes
relate to
ComputeFigure class?
This is for us to see and look at before we try the lab to see what is already there.
You might also be interested in this useful email question and answer
Go to the
Lab Assignments: drop box link and then to lab 4 and follow directions for submission.
In the URL you submit, you should have
So, if some classes do not seem to show up, try one of two fixes