Part 1: Design and implement a class called Sphere that contains instance data that represents the sphere's diameter. The Sphere also includes the following: • A constructor to accept and initialize the diameter, • A default constructor to initialize sphere's diameter to 1, • A copy constructor • getter and setter methods for the diameter • Methods that o calculate and return the volume and surface area of the sphere o A toString method that returns a one-line description of the sphere to include diameter, Surface Area and Volume o An equals method to compare diameters of the spheres and if they are the same the spheres are identical otherwise not. Needed formulas: • volume =, n where r Radius and Radius = Diameter / 2 %3D • Surface area = 4 nr Where r = Radius art 2: eate a driver class called MultiSphere, whose main method instantiates and updates several Sphere objects and prints them to the nitor. the toolhar press ALT+E10(PC)or ALT+EN+E10 (Mac) ave and Submit to save and submit. Click Save All Answers to save all answers.

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter11: Advanced Inheritance Concepts
Section: Chapter Questions
Problem 2GZ
icon
Related questions
Question
.Surface area = 4 Tr Where r = Radius
%3D
rt 2:
te a driver class called MultiSphere, whose main method instantiates and updates several Sphere objects and prints them to the
tor.
e toolbar, press ALT+F10 (PC) or ALT+FN+F10 (Mac).
IUS
Paragraph
Arial
14px
A v
Ix
...
O WORDS POWERED BY TINY
TION 9
Save All Ans
nd Submit to save and submit. Click Save All Answers to save all answers.
MacBook Pro
DII
F10
F9
3.
<>
II
<.
<>
Transcribed Image Text:.Surface area = 4 Tr Where r = Radius %3D rt 2: te a driver class called MultiSphere, whose main method instantiates and updates several Sphere objects and prints them to the tor. e toolbar, press ALT+F10 (PC) or ALT+FN+F10 (Mac). IUS Paragraph Arial 14px A v Ix ... O WORDS POWERED BY TINY TION 9 Save All Ans nd Submit to save and submit. Click Save All Answers to save all answers. MacBook Pro DII F10 F9 3. <> II <. <>
Part 1:
Design and implement a class called Sphere that contains instance data that represents the sphere's diameter.
The Sphere also includes the following:
• A constructor to accept and initialize the diameter,
• A default constructor to initialize sphere's diameter to 1,
A copy constructor
getter and setter methods for the diameter
• Methods that
o calculate and return the volume and surface area of the sphere
o A toString method that returns a one-line description of the sphere to include diameter, Surface Area and Volume
o An equals method to compare diameters of the spheres and if they are the same the spheres are identical otherwise not.
Needed formulas:
4.
ar where r = Radius and Radius = Diameter / 2
3.
• volume
%3D
%3D
• Surface area = 4 nr Where r = Radius
%3D
'art 2:
reate a driver class called MultiSphere, whose main method instantiates and updates several Sphere objects and prints them to the
onitor.
- the toolhar press AIT+F10 (PCor ALT+EN+F10 (Mac)
Save and Submit to save and submit. Click Save All Answers to save all answers.
Save All
MacBook Pro
DII
吕口
O OO
O OO
F9
F 5
F 6
F7
F8
F4
Transcribed Image Text:Part 1: Design and implement a class called Sphere that contains instance data that represents the sphere's diameter. The Sphere also includes the following: • A constructor to accept and initialize the diameter, • A default constructor to initialize sphere's diameter to 1, A copy constructor getter and setter methods for the diameter • Methods that o calculate and return the volume and surface area of the sphere o A toString method that returns a one-line description of the sphere to include diameter, Surface Area and Volume o An equals method to compare diameters of the spheres and if they are the same the spheres are identical otherwise not. Needed formulas: 4. ar where r = Radius and Radius = Diameter / 2 3. • volume %3D %3D • Surface area = 4 nr Where r = Radius %3D 'art 2: reate a driver class called MultiSphere, whose main method instantiates and updates several Sphere objects and prints them to the onitor. - the toolhar press AIT+F10 (PCor ALT+EN+F10 (Mac) Save and Submit to save and submit. Click Save All Answers to save all answers. Save All MacBook Pro DII 吕口 O OO O OO F9 F 5 F 6 F7 F8 F4
Expert Solution
Answer for Part-1:

 public class Sphere {
//a Diameter define
  double diameter;

//define a constructor to define sphere object
  Sphere(double d) {
   diameter = d;
 }
// a getter method to get the Sphere diameter
  double getDiameter() {
  return diameter;
 }
// Volume: formula is 4/3 Pi * R3
  double getVolume() {
  double radius = diameter / 2.0;
  double volume = 4.0 / 3.0 * Math.PI * radius * radius * radius;
  return volume;
 }
// Surface: formula is 4 Pi * R2
  double getSurface() {
  double radius = diameter / 2.0;
  double surface = 4.0 * Math.PI * radius * radius;
  return surface;
 }

 public static void main(String[] arg) {
//2 sphere objects by "instantiating" the class Sphere
  Sphere sphere1 = new Sphere(1.0);
  Sphere sphere2 = new Sphere(2.0);
// display the surface and the volume
  System.out.println("Sphere 1: Diameter: " + sphere1.getDiameter() + " Surface: " + sphere1.getSurface() + " Volume: " + sphere1.getVolume());
  System.out.println("Sphere 2: Diameter: " + sphere2.getDiameter() + " Surface: " + sphere2.getSurface() + " Volume: " + sphere2.getVolume());
 }
}

trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Knowledge Booster
Class
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT