1. Member
Join Date
Aug 2008
Posts
1
Rep Power
0

## Proofreading this small Java program

I've recently got this new spiffy Java textbook, and upon doing one of the programming projects, it appears that I've encountered a problem. The logic of this program appears to be fine, but something sematically appears to have effected it to produce a non-sensical result.

The purpose of this program is to construct a class which computes the surface area and volume of a sphere, and return the values.

Java Code:
```class Sphere
{
private final double FT = 1.333333;
private final double PI = 3.14159;

private double diameter;
private double volume;
private double surfaceArea;

public Sphere (double diameterofSphere)
{
diameterofSphere = diameter;
}

{
}

public double getVolume ()
{
volume = (FT * PI * Math.pow(radius, 3));
return volume;
}

public double getSurfaceArea ()
{
surfaceArea = (4 * PI * Math.pow(radius, 2));
return surfaceArea;
}

public String toString ()
{
return "The surface area and volume of your sphere is: " + surfaceArea +
volume;
}
}

public class SphereData
{
public static void main (String[] args)
{
Sphere sphere1 = new Sphere(100);

sphere1.getVolume();
sphere1.getSurfaceArea();

System.out.println (sphere1);
}
}```
However, this is the output:

Java Code:
`The surface area and volume of your sphere is: 0.00.0`
Thanks for reading. Also, if I'm doing something that's unnecessary, please tell me =)

2. Java Code:
```	public Sphere (double diameterofSphere)
{
//		diameterofSphere = diameter;
diameter = diameterofSphere;
}```

3. Member
Join Date
Oct 2009
Posts
12
Rep Power
0
From the looks of it, radius = diameter / 2; is dividing nothing by 2.

I think the line diameterofSphere = diameter; needs to be diameter = diameterofSphere

EDIT: Just realised that's what the guy before me was saying

4. you may want to put a space in your output. At first I thought something was wrong when i saw 0.00.0, 2 decimals in a number O_O

5. Originally Posted by Lizzip
EDIT: Just realised that's what the guy before me was saying
And a little over a year earlier than you to boot. We appreciate your helping out, but you may want to reply to more recent threads.

6. Member
Join Date
Oct 2009
Posts
12
Rep Power
0
Originally Posted by Fubarable
And a little over a year earlier than you to boot. We appreciate your helping out, but you may want to reply to more recent threads.
Sorry, didn't even notice that D:

#### Posting Permissions

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