aspose file tools*
The moose likes Beginning Java and the fly likes Creating your own class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Creating your own class" Watch "Creating your own class" New topic
Author

Creating your own class

A Issa
Greenhorn

Joined: Mar 26, 2011
Posts: 5

Hi;
I am creating my own class in my program. I am suppose to create a big circle that has another circle inside, another one outside, and finally another one intersecting it. I have a circletester, and a drawing panel. So far this is what I have for my program:

I am suppose to create a public boolean inside(Circle c2) to test if the circle is inside the circle and I am having trouble creating that. If anyone can help I will appreciate. Thanks, A
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38756
    
  23
Your method should have one parameter: test whether the circle passed is inside the current circle. But I wouldn't try that at first. Comment out the inside method and try to write this methodNow you will have to work out whether a point (xx, yy) is inside your circle or outside. You will also have to decide what to do if the point is exactly on your circumference. And to do that you will have to use Pythagoras' theorem: the squaw on the hippopotamus is equal to the sons of the squaws on the other two hides. Once you have that working, you can calculate how far inside the circle that point (xx, yy) is. If the distance inside is greater (or ≥) the radius of the inside circle, then the whole of that circle is inside.

You don't need programming just at the moment. You need a pencil and paper. By the way: there are methods in the java.lang.Math class which can work out some of the calculations for Pythagoras.
A Issa
Greenhorn

Joined: Mar 26, 2011
Posts: 5

Thanks for the respond Campbell. I think I got it. I have another question though, if I want to create 100 random Circle object, each with a random location within the panel and a random radius from 1 to 20 with a loop how can I do that? I know that I need to use an array to do this. But I don't want any circle that intersect the big circle. This is the code that I have so far:
A Issa
Greenhorn

Joined: Mar 26, 2011
Posts: 5

Nevermind on the last post. I got it

Thanks,
A
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38756
    
  23
Don't use Math.pow(x, 2) to square x. Write x * x.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Creating your own class