Question: design a public class named Sphere (which is a 3 dimensional circle) to represent a sphere in Java. The class contains: a private double data

design a public class named Sphere (which is a 3 dimensional circle) to represent a sphere in Java.

The class contains:

a private double data field radius with a default value of 1.0

Two constructor methods:

A no-argument constructor that creates a default sphere

A constructor that creates a sphere with the specified radius

Getter and setter methods:

A method named getRadius() that returns the sphere's radius

A method named setRadius(newRadius) that sets the sphere's radius

A method named getSurfaceArea() that returns the sphere's surface area surface area = 4 * * radius2

A method named getVolume() that returns the sphere's volume volume = 4/3 * radius3

Write a simple test program like we did in class that creates two Sphere objects: sphere1 with radius = 6.3 sphere2 with a randomly generated radius from 25 to 50 (including 25, excluding 50) using the setRadius method

Display the radius, surface area, and volume of each sphere to two decimal places. For full marks, include a screenshot output of the program to demonstrate that it worked .

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!