Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

please fix my code i am receving an error. Design and implement a class called Sphere that contains instance data that represents the sphere's diameter.

please fix my code i am receving an error.

Design and implement a class called Sphere that contains instance data that represents the sphere's diameter. ? Define the Sphere constructor to accept and initialize the diameter, ? include getter and setter methods for the diameter. ? Include methods that calculate and return the volume and surface area of the sphere ? Create a driver class called MultiSphere, whose main method instantiates and updates several Sphere objects.

//Sphere.java public class Sphere { private double diameter;

public Sphere(double diameter) { this.diameter = diameter; }

public double getDiameter() { return diameter; }

public void setDiameter(double diameter) { this.diameter = diameter; }

public double getVolume(){ double r = diameter/2; return (4.0/3.0)*Math.PI*r*r*r; }

public double getArea(){ double r = diameter/2; return 4.0*Math.PI*r*r; }

public String toString() { return "Sphere{" + "diameter=" + diameter + '}'; } }

//MultiSphere.java public class MultiSphere { public static void main(String args[]) { Sphere sphere1 = new Sphere(5); System.out.println(sphere1.getArea()); System.out.println(sphere1.getVolume()); sphere1.setDiameter(10); System.out.println(sphere1.getArea()); System.out.println(sphere1.getVolume());

Sphere sphere2 = new Sphere(15); System.out.println(sphere2); } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Structured Search For Big Data From Keywords To Key-objects

Authors: Mikhail Gilula

1st Edition

012804652X, 9780128046524

More Books

Students also viewed these Databases questions

Question

LO6 List the components of job descriptions.

Answered: 1 week ago

Question

What do Dimensions represent in OLAP Cubes?

Answered: 1 week ago