Welcome to Dream.In.Code
Become a Java Expert!

Join 149,501 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 1,371 people online right now. Registration is fast and FREE... Join Now!




circle intersection

 
Reply to this topicStart new topic

circle intersection

prit876
20 Mar, 2007 - 05:03 PM
Post #1

New D.I.C Head
*

Joined: 7 Mar, 2007
Posts: 5


My Contributions
CODE

        public class Circle {
    private double radius;
    private int centerX;
    private int centerY;
    
    public Circle( double radiusValue )
    {
        setRadius( radiusValue );
    }
    
    public void setRadius( double radiusValue )
    {
        radius = radiusValue;
    }
    
    public double getRadius()
    {
        return radius;
    }
    
    public Circle( int centerXPoint )
    {
        setCenterX( centerXPoint );
    }
    
    public void setCenterX( int centerXPoint )
    {
        centerX = centerXPoint;
    }
    
    public double getCenterX()
    {
        return centerX;
    }
    
        public Circle( int centerYPoint )
    {
        setCenterY( centerYPoint );
    }
    
    public void setCenterY( int centerYPoint )
    {
        centerY = centerYPoint;
    }
    
    public double getCenterY()
    {
        return centerY;
    }
    
    public double getCircumference()
    {
        return Math.PI * getRadius() * 2;
    }
    
    public double getArea()
    {
        return Math.PI * getRadius() * getRadius();
    }
}


I Keep getting an error called Circle(int) is already defined in circle in line 44... What else can an int be?
User is offlineProfile CardPM
+Quote Post

keems21
RE: Circle Intersection
20 Mar, 2007 - 09:36 PM
Post #2

D.I.C Head
Group Icon

Joined: 3 Feb, 2007
Posts: 183



Thanked: 2 times
Dream Kudos: 25
My Contributions
These two methods are what are giving you problems:
CODE

public Circle( int centerXPoint )
    {
        setCenterX( centerXPoint );
    }

and
CODE

public Circle( int centerYPoint )
    {
        setCenterY( centerYPoint );
    }


What you're having trouble with here is your method signature. Both of these two methods have the same name (Circle()) and both take the same arguement (an int).

So, the problem arrises when you call the method Circle() in your main method. Say you type something like Circle(5). With code like that, Java doesn't know whether to call the first Circle() method or the second one.

Now, using the same method name for multiple methods is a nice thing that Java allows us to do. The only condition, is that you need the method signature to be different in order for the compiler to know which one to call in a given situation.
For instance, all of these methods are good:
CODE

Circle(int x) {}
Circle(int x, int y) {}
Circle(int x, int y, String s) {}
...and so on


With all of that said, we're onto the solution. To be honest, I'm not sure why you have the method Circle() to begin with because in reality, all it is doing is calling another method, either setCenterX( centerXPoint ) or setCenterY( centerYPoint ). I would say, get rid of the two Circle() methods all together, then whereever you called the Circle() method in your main method, use either setCenterX( centerXPoint ) or setCenterY( centerYPoint ).

Let me know how that works out.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/7/09 06:38PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month