programming forums Java Java JSRs Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Products This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Sheriffs:
Saloon Keepers:
Bartenders:

# Creating your own class

Greenhorn
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

Marshal
Posts: 57437
175
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
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
Posts: 5
• 1
Nevermind on the last post. I got it

Thanks,
A

Campbell Ritchie
Marshal
Posts: 57437
175
• 1
Don't use Math.pow(x, 2) to square x. Write x * x.

 Destroy anything that stands in your way. Except this tiny ad: The WEB SERVICES and JAX-RS Course https://coderanch.com/t/690789/WEB-SERVICES-JAX-RS