Results 1 to 6 of 6
- 10-03-2012, 02:12 PM #1
Member
- Join Date
- Oct 2012
- Posts
- 2
- Rep Power
- 0
Constructor problems. New to java
and this is my DriverJava Code:public class Sphere { private double diameter; double r; double sr; double vr; public Sphere(){ this.diameter = 0;} public void setDiameter(double d){ this.diameter = d;} public double getDiameter(){ return diameter;} public double getVolume(){ r = ( diameter / 2 ); vr = ( r * r * r ); double v = ( 4 / 3 ) * (Math.PI * vr); return v;} public double getSurface(){ r = ( diameter / 2); sr = ( r * r ); double sa = ( 4 ) * (Math.PI * sr); return sa; } public String toString(){ String result = ("The Sphere that has a: " + " " + diameter + "diameter" + " , has " + volume + " volume , and " + surface + " surface area"); return result; } }
My Problem is that I am not able to display this messageJava Code:public class MultiSphere{ public static void main(String[] args){ Sphere sphere1 = new Sphere(); Sphere sphere2 = new Sphere(); sphere1.setDiameter(55); sphere2.setDiameter(88); sphere1.getSurface(); sphere1.getVolume(); sphere2.getSurface(); sphere2.getVolume(); System.out.println(sphere1); System.out.println(sphere2); } }Without getting an error that it cannot find the symbol.Java Code:String result = ("The Sphere that has a: " + " " + diameter + "diameter" + " , has " + volume + " volume , and " + surface + " surface area");
- 10-03-2012, 02:40 PM #2
Re: Constructor problems. New to java
Please post the full text of the error message.an error that it cannot find the symbol.If you don't understand my response, don't ignore it, ask a question.
- 10-03-2012, 02:44 PM #3
Re: Constructor problems. New to java
Code Conventions for the Java Programming Language: Contents -- particularly the section on proper indenting.
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 10-03-2012, 02:46 PM #4
Member
- Join Date
- Oct 2012
- Posts
- 2
- Rep Power
- 0
Re: Constructor problems. New to java
C:\Users\user\Desktop\Java Files\Sphere.java:33: error: cannot find symbol
String result = ("The Sphere that has a: " + " " + diameter + "diameter" + " , has " + volume + " volume , and " + surface + " surface area");
^
symbol: variable volume
location: class Sphere
C:\Users\user\Desktop\Java Files\Sphere.java:33: error: cannot find symbol
String result = ("The Sphere that has a: " + " " + diameter + "diameter" + " , has " + volume + " volume , and " + surface + " surface area");
^
symbol: variable surface
location: class Sphere
2 errors
Tool completed with exit code 1
- 10-03-2012, 04:05 PM #5
Moderator
- Join Date
- Apr 2009
- Posts
- 10,438
- Rep Power
- 16
Re: Constructor problems. New to java
Where have you defined either of those variables?
Please do not ask for code as refusal often offends.
- 10-03-2012, 05:52 PM #6
Member
- Join Date
- Feb 2012
- Posts
- 18
- Rep Power
- 0
Similar Threads
-
Java - Constructor Method versus Constructor
By brocksoffice in forum New To JavaReplies: 1Last Post: 08-01-2012, 09:17 AM -
Problems calling a class with constructor throws Exception
By brrrr in forum New To JavaReplies: 4Last Post: 04-22-2012, 09:22 PM -
Problems with Timer Constructor
By Yids in forum AWT / SwingReplies: 3Last Post: 03-11-2011, 05:35 AM -
Problems with Timer Constructor
By Yids in forum New To JavaReplies: 2Last Post: 03-10-2011, 04:56 PM -
problems with asigning elements of an array to a constructor
By rednessc in forum New To JavaReplies: 1Last Post: 12-14-2007, 07:25 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks