This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help with Circle Class :)

 
Mike Pirrone
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Dave Vick
Ranch Hand
Posts: 3244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ryan Perlman
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you so much guys. your url did not work though at the bottom. but its cool. much thanks
 
Ryan Perlman
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic