File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Creating your own class

 
A Issa
Greenhorn
Posts: 5
Eclipse IDE Firefox Browser Mac
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 47229
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Eclipse IDE Firefox Browser Mac
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Eclipse IDE Firefox Browser Mac
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nevermind on the last post. I got it

Thanks,
A
 
Campbell Ritchie
Sheriff
Pie
Posts: 47229
52
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't use Math.pow(x, 2) to square x. Write x * x.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic