I'm creating a program that returns the values of a sphere's diameter, surface area, and volume. Heres the class I made to make a sphere object, there is probably something wrong with it. Please help identify what I'm doing wrong.
now heres the program i made to display the information of a sphere with a radius of 10.
Thanks for the help in advance.
Code:
package sphere;
public class Sphere {
//attributes
private double radius;
private double PI = 3.14159265;
/** Creates a new instance of Main */
public Sphere(){
}
// radius mutator
public void setRadius(double r){
radius = r;
}
// returns the radius
public double getRadius(){
return radius;
}
// returns the diameter
public double getDiameter(){
double diameter = radius + radius;
return diameter;
}
//returns the volume of the sphere
public double getVolume(){
double volume = (4/3)*PI*(Math.pow(radius, 3));
return volume;
}
// Returns the surface area of the sphere
public double getSurfaceArea(){
double surfaceArea = 4*PI*(Math.pow(radius, 2));
return surfaceArea;
}
// returns a string
public String toString(){
return "Radius = " + radius + " Diameter = " + diameter + " Volume = " + volume + " Surface area = " + surfaceArea;
}
}
now heres the program i made to display the information of a sphere with a radius of 10.
Code:
package sphere;
public class SphereTester {
/** Creates a new instance of SphereTester */
public static void main(String [] args){
SphereTester spheretester = new SphereTester();
Sphere mySphere = new Sphere();
mySphere.setRadius(10);
mySphere.getDiameter();
mySphere.getSurfaceArea();
mySphere.getVolume();
System.out.println(mySphere);
}
}
Thanks for the help in advance.