This week's book giveaway is in the Jobs Discussion forum. We're giving away four copies of Customer Requirements for Developers and have Marcho Behler on-line! See this thread for details.

I am trying to create an applet that draws 20,000 points at random within an area with x values from 0 to 300 and y values from 0 to 300. Each point is to be drawn as a line of length 0. A circle is to be centered at (150,150) and with a radius of 75. The points with in the circle are to be green and red if outside the circle. Then when all the points have been generated, a computated ratio of the points inside the circle to the total number of points, then display that as well. Also a display of 16 times this ratio. Here is what I have so far.

any suggestions are needed, I just need a jump start on completing this. Not sure what to do next or if I'm even headed in the correct direction.

so your trying to compute the value of Pi, huh??? ;-) i'm not sure what your going with in your "if" statement. you don't have an x or a y yet, and then if it meets some condition, you're going to increment a counter that starts at 20,000?

1) you need a way to get a random number between 0 and 300. 2) you need to be able to store 2 of these while you do some computations. 3) you need to figure out if this point is inside or outside the circle (which is almost what your 'if' condition was doing 4) you need to keep a counter of whether this was inside or outside the circle. 5) you need to be able to draw the point, and set it's color 6) you need a way to do this 20,000 times. 7) you need to figure out the ratio 8) you need to draw the circle 9) you need to draw the square 10) you need to display the ratio note that you don't have to follow this EXACT order. you could try drawing the circle and square before figuring out the points, or the other way around. don't try and do it all at the same time. pick what seems like a logical one to start with, get that to work, TEST IT THOROUGHLY, and only when your SURE that part works, start the next part. If you try and do it all at once, you'll be overwhellmed. Oh, and as you keep adding new parts, keep going back and testing the old stuff. if you keep track of the bugs you found and what you did to reveal that bug, REPEAT THOSE TEST after every step. as you get code written, feel free to post it and ask more questions!!! this is much more enjoyable to me than doing my work.

There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors

page.drawOval (150, 150, 75, 75) will not give you a circle indicatd in the statement. Unless you are overridding drawOval(). The parameter should be (75,75,150,150).

A circle is to be centered at (150,150) and with a radius of 75.

[ April 22, 2004: Message edited by: chi Lin ]

not so smart guy still curious to learn new stuff every now and then