CSCI 111 LAB 4

Lab Times: See course home page

TA: See course home page

Worth:20 points


API

Computations and Variables

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.

  1. Similar to lab 3, create a directory under your public_html/csci111/lab4 directory where the files for this assignment should be placed. Copy the following files
      cp ~amk/courses/csci15a/15a_examples/lab4/ComputeFigure.java . cp ~amk/courses/csci15a/15a_examples/lab4/example4.html . cp ~amk/courses/csci15a/15a_examples/lab4/makefile .
    You should use the make utility to compile the provided source to confirm it is error free and that it works as advertised. You should test it by opening its html page example4.html using your favorite browser (Firefox, IE, etc.). See
    this page for a reminder on makefiles (and some added information).

  2. Modify the ComputeFigure.java file to compute the area, perimeter and center point of the draw figures. Before starting, examine the provided code and get a feeling for how it works first. Your final applet should display the computed values using the drawString method, see if you can do it without writing over the displayed figure. All output should be meaningful and labeled, don't just print a a bunch of numbers. You may need to declare some variables, so make sure you use meaningful variable names. Also watch for integer math computations, this may result in unexpected results.

    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..

    Circle
    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).

    Square
    area = hw		height times width
    perimeter=2h+2w 2 times height plus 2 times width

    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.

    	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)

  3. README information:
    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?

  4. Submission:

    Web Page Submission Required Contents:
    In the URL you submit, you should have

    1. your applet running,
    2. provide a link to source code,
    3. a link to the javadoc created page, and
    4. the answers to the questions in #3 (in a README link on the web page).