• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Creating your own class

 
Greenhorn
Posts: 5
Mac Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Marshal
Posts: 79153
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Mac Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Mac Eclipse IDE Firefox Browser
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Nevermind on the last post. I got it

Thanks,
A
 
Campbell Ritchie
Marshal
Posts: 79153
377
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Don't use Math.pow(x, 2) to square x. Write x * x.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic