Two Laptop Bag*
The moose likes Beginning Java and the fly likes Help with Circle Class  :) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Help with Circle Class  :)" Watch "Help with Circle Class  :)" New topic
Author

Help with Circle Class :)

Mike Pirrone
Ranch Hand

Joined: Oct 30, 2001
Posts: 33
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).]
Peter Chase
Ranch Hand

Joined: Oct 30, 2001
Posts: 1970
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.
Dave Vick
Ranch Hand

Joined: May 10, 2001
Posts: 3244
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


Dave
Ryan Perlman
Greenhorn

Joined: Oct 31, 2001
Posts: 23
Hello I am just another student who has done a similar problem
Here is the web page to the source:
http://ryanperlman.tripod.com/school/your_circle.htm
hope that helps
Mike Pirrone
Ranch Hand

Joined: Oct 30, 2001
Posts: 33
Thank you so much guys. your url did not work though at the bottom. but its cool. much thanks
Ryan Perlman
Greenhorn

Joined: Oct 31, 2001
Posts: 23
http://ryanperlman.tripod.com/school/yourcircle_source.htm
Here's that url again sorry for the last one not being correct
http://ryanperlman.tripod.com/schoo/java.htm
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Help with Circle Class :)