Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Given the following program, answer the following questions: import Java.text.De

ID: 3821992 • Letter: G

Question

Given the following program, answer the following questions: import Java.text.DecimalFormat; class Sphere Test { public static void main (String[] args) { DecimalFormat fmt = new DecimalFormat(0.00): Sphere s1 = newsphere (5); System.out.println (s1); s1.setDiameter(9); System.out.println (s1); System.out.println(The area = + fmt.format(s1.area(s1.getDiameter[]): System.out.printin[The volume = + fmt.format(s1.volume(s1.getDiameter[])); } public static class Sphere { private int diameter; public Sphere (int diam) { diameter = diam; } public Int getDiameter() { return diameter; } public void setDiameter (int diam) { diameter = diam; } public double area (int diameter) { return Math.PI*Math.pow(diameter, 2); } public double volume (int diameter) { return (Math.PI/6.)*Math.pow(diameter, 3); } public String toString () { DecimalForm fmt = new DecimalFormat(0.00); return Diameter: + diameter + Area = + fmt.format[area(diameter)] + Volume = + fmt.format(volume(diameter) ; } } }

Explanation / Answer

a)
Driver program is SphereTest

b)
Class name os Sphere

c)
Constructor name is Sphere

d)
accessor name is getDiameter

e)
mutator name is setDiameter

f)
s1 is the object creatd in driver

g)
s1 is the object passes to print


Sample run:
Diameter: 5       Area = 78.50    Volume = 65.42
Diameter: 9       Area = 254.34    Volume = 381.51
The area = 254.34
The volume = 381.51

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote