← Back to Classes
Question 149
Build a Sphere Class
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()using4π*r², andtoString()that returns the formatted string with radius, volume, and surface area each rounded to 2 decimals. ThetoString()method should return a string in this format: Radius: 5.00 Volume: 523.60 Surface area: 314.16 UseString.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.