Results 1 to 6 of 6
  1. #1
    Jaybond63 is offline Member
    Join Date
    Oct 2012
    Posts
    2
    Rep Power
    0

    Default Constructor problems. New to java

    Java 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;
    }
    
    }
    and this is my Driver

    Java 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);
    
    
    
    
    }
    }
    My Problem is that I am not able to display this message
    Java Code:
    String result = ("The Sphere that has a: " + " " + diameter + "diameter" + " , has " + volume + " volume , and " + surface + " surface area");
    Without getting an error that it cannot find the symbol.

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,518
    Rep Power
    25

    Default Re: Constructor problems. New to java

    an error that it cannot find the symbol.
    Please post the full text of the error message.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,305
    Rep Power
    20

    Default Re: Constructor problems. New to java

    Code Conventions for the Java Programming Language: Contents -- particularly the section on proper indenting.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  4. #4
    Jaybond63 is offline Member
    Join Date
    Oct 2012
    Posts
    2
    Rep Power
    0

    Default Re: Constructor problems. New to java

    Quote Originally Posted by Norm View Post
    Please post the full text of the error message.
    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

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,050
    Rep Power
    20

    Default Re: Constructor problems. New to java

    Where have you defined either of those variables?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  6. #6
    Akirien is offline Member
    Join Date
    Feb 2012
    Posts
    18
    Rep Power
    0

    Default Re: Constructor problems. New to java

    The error stated everything.. Like Tolls said, where have you defined those variables? Surface and Volume.

Similar Threads

  1. Java - Constructor Method versus Constructor
    By brocksoffice in forum New To Java
    Replies: 1
    Last Post: 08-01-2012, 09:17 AM
  2. Replies: 4
    Last Post: 04-22-2012, 09:22 PM
  3. Problems with Timer Constructor
    By Yids in forum AWT / Swing
    Replies: 3
    Last Post: 03-11-2011, 05:35 AM
  4. Problems with Timer Constructor
    By Yids in forum New To Java
    Replies: 2
    Last Post: 03-10-2011, 04:56 PM
  5. Replies: 1
    Last Post: 12-14-2007, 07:25 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •