• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Help with Circle Class :)

 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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).]
 
Ranch Hand
Posts: 1970
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 3244
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic