Ok, I am in a beginning java class and cannot figure out this problem. The purpose of this program is to call upon a class (Circle) and compute the radius and area of the circle. when i compile though, i get this following error: A:\TestCircle.java:12: Incompatible type for method. Can't convert void to char. System.out.print(circle1.computeDiameter()); Here is my source code: For my Circle Class
I really appreciate any form of help. Thank you so much! -mike- (edited to format the code - Dave) [This message has been edited by Dave Vick (edited October 30, 2001).]
You try to print the result of computeDiameter(), but that method has a void return - it stores the result in the member variable. Instead, you need to call computeDiameter(), then separately print the member variable. Either that, or change the computeDiameter() method to return the diameter it has computed.
Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.
Mike The short answer for your error: You're calling the method computeDiameter() in the println method. Your computeDiameter() method returns void and println can't print void. The long answer: In your circle class you have the area and diameter variables set as private but you have no accessor methods to get at the values once they've been set with computeArea or computeDiameter. You could just have methods called getDiameter and getArea that do the calculation each time and return a float as an answer. Then all you'd have to do is store the radius as a variable and the various get methods would calculate their answers when they are called. If you store the values for diameter and area then you'll have to recalculate them each time the radius changes. hope that helped, it was probably more of answer than you were looking for
------------------ Dave Sun Certified Programmer for the Java� 2 Platform