Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1. You will create a Java Class called Sphere. The class should have the following: Constructor: New() Zero parameter. Creates a Sphere with a radius

1. You will create a Java Class called Sphere. The class should have the following:

Constructor: New() Zero parameter. Creates a Sphere with a radius of zero

Constructor: New(double) Creates a Sphere with the initial radius specified. If the radius specified is less than zero, the Sphere should be constructed with a radius of Zero

Methods:

double volume() Should return the volume of the Sphere

double surfaceArea() Should return the surface area of the Sphere

setRadius( double NewRadius) Should set the radius of the Sphere to the NewRadius provided NewRadius >= 0. If NewRadius <0, no change to the Sphere.

double getRadius( ) Should return the radius of the Sphere

String toString() should return the String representation of the Sphere

Sphere needs to implement the Comparable interface. The comparison should be based upon the size of the Radius.

You must include a main method with appropriate test(s). Remember what an appropriate level of testing includes.

Your Sphere must also include javadoc comments and tags for the class, and all methods and constructors.

here.java file:

public class Sphere implements Comparable{ private double radius ;

public Sphere() { this.radius = 0 ; }

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

public double getRadius() { return radius; }

public void setRadius(double radius) { this.radius = radius; } public double volume() { return (4.0/3.0) * Math.PI * this.radius * this.radius * this.radius ; } public double surfaceArea() { return 4 * Math.PI * this.radius * this.radius ; } public String toString() { return "Sphere [radius=" + radius + "]"; } @Override public int compareTo(Object o) { Sphere other = (Sphere) o; if(this.radius > other.radius) return 1 ; else if(this.radius < other.radius) return -1 ; return 0; } }

TestSphere.java file:

public class TestSphere {

public static void main(String[] args) {

Sphere s1 = new Sphere(5); System.out.println("Sphere1 : " + s1); System.out.println("Volume : " + s1.volume()); System.out.println("Surface area : " + s1.surfaceArea());

}

}

Please do this with the "New" constructors thank you.

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

Database Systems Design Implementation And Management

Authors: Peter Robb,Carlos Coronel

5th Edition

061906269X, 9780619062699

More Books

Students also viewed these Databases questions

Question

1. Differentiate between a command system and a market system.

Answered: 1 week ago

Question

1. Which is the most abundant gas presented in the atmosphere?

Answered: 1 week ago