This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Help with Circle Class  :)" Watch "Help with Circle Class  :)" New topic

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:\ Incompatible type for method. Can't convert void to char[].
Here is my source code:
For my Circle Class

I really appreciate any form of help. Thank you so much!
(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
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

Sun Certified Programmer for the Java� 2 Platform

Ryan Perlman

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:
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

Joined: Oct 31, 2001
Posts: 23
Here's that url again sorry for the last one not being correct
Consider Paul's rocket mass heater.
subject: Help with Circle Class :)
Similar Threads
question about this code
Circle program errors
Class get and set explanation
Programing challenge
Simple program question