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...
Implement the Nickel class. Include Javadoc comments for the class, public fields, constructors, and methods of...
Implement the Nickel class. Include Javadoc comments for the class, public fields, constructors, and methods of the class. I have added the Javadoc comments but please feel free to format them if they are done incorrectly. public class Nickel implements Comparable { private int year; /** * The monetary value of a nickel in cents. */ public final int CENTS = 5; /** * Initializes this nickel to have the specified issue year. * * @param year * * @pre....
Create a footer for web page using HTML,CSS,Javascript. The footer should contain 1.Back to top button...
Create a footer for web page using HTML,CSS,Javascript. The footer should contain 1.Back to top button 2.Random logo 3.Copyright content
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...
write the program in java. Develop a class RentCabin that does the following: (use JavaDoc comments)...
write the program in java. Develop a class RentCabin that does the following: (use JavaDoc comments) // declare the constructor that sets the type and rate based in the sqft parm        // set values based on sqft <1000 is small with $100 per night, // sqft between 1000 and 2000, mid-sized $200 per night, and // over 2000 as a large cabin with $300 per night        //declare getRate        //declare getType        //declare setRate with int rate parm...
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....
In java, (include javadoc comments for each method) design a class named Contacts that has fields...
In java, (include javadoc comments for each method) design a class named Contacts that has fields for a person’s name, phone number and email address. The class should have a no-arg constructor and a constructor that takes in all fields, appropriate setter and getter methods. Then write a program that creates at least five Contacts objects and stores them in an ArrayList. In the program create a method, that will display each object in the ArrayList. Call the method to...
1) Only a single main class is required 2) The main class must contain a static...
1) Only a single main class is required 2) The main class must contain a static method called "getInputWord" that prompts a user to input a word from the keyboard and returns that word as a String. This method must use "JOptionPane.showInputDialog" to get the input from the user (you can find info about JOptionPane in JavaDocs) 3) The main class must contain a static method called "palindromeCheck" that takes a String as an input argument and returns a boolean...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT