CJCoding With Joseph
15per day

Build a Sphere Class

Complete the Sphere class with: a constructor that stores the radius, getRadius(), setRadius(double r), getVolume() using (4/3)π*r³, getSurfaceArea() using 4π*r², and toString() that returns the formatted string with radius, volume, and surface area each rounded to 2 decimals.

The toString() method should return a string in this format:
Radius: 5.00
Volume: 523.60
Surface area: 314.16

Use String.format("%.2f", value) for formatting.

Do NOT write a main method.

Expected Output:

Radius: 5.00
Volume: 523.60
Surface area: 314.16
Topics:
Classes
Code Editor
1
Tab to indent · Ctrl+Enter to run · Ctrl+Space to expand shortcuts (sysout, psvm, fori)

Your Output

Run your code to see the output here...

Test Cases

Run your code to see test case results.