Question

In: Computer Science

1. a.Include a Javadoc comment at the top of the class. The Javadoc comment should contain:...

1.

a.Include a Javadoc comment at the top of the class. The Javadoc comment should contain:

i.The name of the class and a (very) short description

ii.An @author tag followed by your name

iii.An @version tag followed by the version number.

b.Do not include a main method inside the class definition. Remember the main method is what gets executed first when we start our program. In this case, the Sphere class is not a complete program. It will simply be used to represent a Sphere concept. We will create our main method in a separate Driver class.

2.A Sphere is defined mathematically as the set of points in 3D space that are all at the same distance r (radius) from a given point. This suggests that a Sphere should have instance variables that represent the following:

a.X-coordinate

b.Y-coordinate

c.Z-coordinate 1

d.Radius.

3.The Sphere class needs a constructor which accepts a parameter for each of these four attributes, and assigns the value to the respective instance variable.

4.Create an accessor and a mutator for each instance variable.

5.Create a method that returns the surface area of the Sphere. The formula for the surface area A of a sphere of radius r =4휋푟!.

6.Create a method that returns the volume of the Sphere. The formula for the volume V of a sphere of radius r ="#휋푟#.

7.Create a toString()method which returns a String composed of the concatenation of the information in the Sphere. Customarily the toString() is the last method in the class

Solutions

Expert Solution

- Kindly upvote if this helped

CODE:

- Please note that I have added a main method just for testing. Please remove it as it is mentioned in the question not to write main method in same java file

/**
 * @author Aman Kaushik - <Write you name here>
 * @version 1.1 <Give a version of your choice here>
 * @param request
 * @return gives a layout of the class Sphere and has methods to compute surface area and volume of sphere
 */
public class Sphere {
        double X , Y , Z , radius;
public double getX() {
                return X;
        }
        public void setX(double x) { // mutator
                X = x;
        }
        public double getY() { // accessor
                return Y;
        }
        public void setY(double y) {
                Y = y;
        }
        public double getZ() {
                return Z;
        }
        public void setZ(double z) {
                Z = z;
        }
        public double getRadius() {
                return radius;
        }
        public void setRadius(double radius) {
                this.radius = radius;
        }
Sphere(){
        X = 0;
        Y = 0;
        Z = 0;
        radius = 0;
}
Sphere(int X , int Y , int Z , int radius){
        this.X = X;
        this.Y = Y;
        this.Z = Z;
        this.radius = radius;
}

public double getSurfaceArea() {
        return 4 * Math.PI * radius * radius; // 4 pi r square
}

public double getVolume() {
        return (4/3) * (Math.PI * radius * radius * radius); // 4/3 pi r cube
}

public String toString() {
        return "Sphere with radius "+this.radius+" has volume = "+this.getVolume()+" and surface area = "+this.getSurfaceArea();
}

public static void main(String[] args) {
        Sphere s = new Sphere(10 , 20 ,20 , 11);
        System.out.print(s.toString());
}

}



Sample output


Related Solutions

Create a class named GameCharacter to define an object as follows: The class should contain class...
Create a class named GameCharacter to define an object as follows: The class should contain class variables for charName (a string to store the character's name), charType (a string to store the character's type), charHealth (an int to store the character's health rating), and charScore (an int to store the character's current score). Provide a constructor with parameters for the name, type, health and score and include code to assign the received values to the four class variables. Provide a...
Create a custom Exception named IllegalTriangleSideException. Create a class named Triangle. The Triangle class should contain...
Create a custom Exception named IllegalTriangleSideException. Create a class named Triangle. The Triangle class should contain 3 double variables containing the length of each of the triangles three sides. Create a constructor with three parameters to initialize the three sides of the triangle. Add an additional method named checkSides with method header - *boolean checkSides() throws IllegalTriangleSideException *. Write code so that checkSides makes sure that the three sides of the triangle meet the proper criteria for a triangle. It...
Create a custom Exception named IllegalTriangleSideException. Create a class named Triangle. The Triangle class should contain...
Create a custom Exception named IllegalTriangleSideException. Create a class named Triangle. The Triangle class should contain 3 double variables containing the length of each of the triangles three sides. Create a constructor with three parameters to initialize the three sides of the triangle. Add an additional method named checkSides with method header - *boolean checkSides() throws IllegalTriangleSideException *. Write code so that checkSides makes sure that the three sides of the triangle meet the proper criteria for a triangle. It...
AskInfoPrintInfo Write a program called AskInfoPrintInfo. It should contain a class called AskInfoPrintInfo that contains the...
AskInfoPrintInfo Write a program called AskInfoPrintInfo. It should contain a class called AskInfoPrintInfo that contains the method main. The program should ask for information from the user and then print it. Look at the examples below and write your program so it produces the same input/output. Examples (the input from the user is in bold face) % java AskInfoPrintInfo enter your name: jon doe enter your address (first line): 23 infinite loop lane enter your address (second line): los angeles,...
• The first tab should contain the simulation model. • The second tab should contain the...
• The first tab should contain the simulation model. • The second tab should contain the algebra of the optimization model. • The third tab should contain the optimization model and its solution using Excel Solver. Q1. Construct a spreadsheet simulation model for calculating profits for a company given that the demand for their new product is normally distributed with a mean of 6 and a standard deviation of 1. The selling price is $30/unit. The fixed cost is $50....
Design a class named Message to represent a sentence or phrase. The class will contain: •...
Design a class named Message to represent a sentence or phrase. The class will contain: • a private string data field to hold the sentence or phrase. • A no-arg constructor with an empty string message. • A constructor that create a message object with the specified string sentence or phrase. • Accessor and mutator (getter/setter) for string data field. • A method named getVowels ( ) that returns the number of vowels in a sentence or phrase. • A...
Create java Class with name Conversion. Instructions for Conversion class: The Conversion class will contain methods...
Create java Class with name Conversion. Instructions for Conversion class: The Conversion class will contain methods designed to perform simple conversions. Specifically, you will be writing methods to convert temperature between Fahrenheit and Celsius and length between meters and inches and practicing overloading methods. See the API document for the Conversion class for a list of the methods you will write. Also, because all of the methods of the Conversion class will be static, you should ensure that it is...
Create a Class to contain a customer order Create attributes of that class to store Company...
Create a Class to contain a customer order Create attributes of that class to store Company Name, Address and Sales Tax. Create a public property for each of these attributes. Create a class constructor without parameters that initializes the attributes to default values. Create a class constructor with parameters that initializes the attributes to the passed in parameter values. Create a behavior of that class to generate a welcome message that includes the company name. Create a Class to contain...
Write a C program that does the following. (a) Start with comment statements at the top...
Write a C program that does the following. (a) Start with comment statements at the top (before your includes) with the following info: Name, Date (b) Write the following functions: void setupRandArray(int n, int x[], int min, int max) void printArray(int n, int x[], char label[]) float getAverage(int n, int x[]) int getMaximum(int n, int x[]) int getCountInRange(int n, int x[], int min, int max) Note: This function returns the number elements of x that are between min and max...
Create a class called Sphere. The class will contain the following    Instance data double radius...
Create a class called Sphere. The class will contain the following    Instance data double radius Methods Constructor with one parameter which will be used to set the radius instance data Getter and Setter for radius             Area - calculate the area of the sphere (4 * PI * radius * radius)             Volume - calculate and return the volume of the sphere (4/3 * PIE * radius * radius * radius) toString - returns a string with the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT