← 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 the exact format shown in Expected Output. UseString.format("%.2f", value)for formatting. Do NOT write a main method.
Expected Output:
Radius: 5.00 Volume: 523.60 Surface area: 314.16
= newline. The output ends with a newline — print one after the last line.
Hints4 available
Sign in to use hintsTopics:
Classes
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · 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.