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...
*// 1- Add JavaDoc to This classes 2- Mak a UML */ import java.util.*; public class...
*// 1- Add JavaDoc to This classes 2- Mak a UML */ import java.util.*; public class Display { public static void main(String[] args) { altEnerCar car1 = new altEnerCar(20000, 2001, 20000); altEnerCar car2 = new HydrogenCar(0, 2012, 50000, 100, false); altEnerCar car3 = new ElectricCar(0, 2014, 30000, 10, 50); altEnerCar car4 = new NaturalGasCar(0, 2000, 60000, 5, 20); altEnerCar car5 = new PropaneCar(0, 2011, 45000, 10, true); ArrayList<altEnerCar> cars = new ArrayList<altEnerCar>(); cars.add(car1); cars.add(car2); cars.add(car3); cars.add(car4); cars.add(car5); Collections.sort(cars); System.out.println(cars); }...
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....
Define a class to represent a Temperature. Your class should contain Instance variable int fahrenheit A...
Define a class to represent a Temperature. Your class should contain Instance variable int fahrenheit A parameterized constructor; Member method to calculate the equivalent temperature in Celsius unit toCelsius() with decimal value. double toCelsius() Conversion formula: celsius= (fahrenheit - 32) * 5/9 Method definition to override the equals() method boolean equals(Object obj)
The Tokenizer.java file should contain: A class called: Tokenizer Tokenizer should have a private variable that...
The Tokenizer.java file should contain: A class called: Tokenizer Tokenizer should have a private variable that is an ArrayList of Token objects. Tokenizer should have a private variable that is an int, and keeps track of the number of keywords encountered when parsing through a files content. In this case there will only be one keyword: public. Tokenizer should have a default constructor that initializes the ArrayList of Token objects Tokenizer should have a public method called: tokenizeFile tokenizeFile should...
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...
Define and implement class Course. This class should contain the following fields: course name, course description,...
Define and implement class Course. This class should contain the following fields: course name, course description, department, time the course starts, weekday the course is held on (for simplicity, let us assume the course only meets once a week). This class should contain getters and setters for all its attributes. This class also needs at least one constructor. Save this class and its definition into a file named Course.java. Define and implement class Student. This class should contain the following...
1. In c++, Class D is derived from class B. The class D does not contain...
1. In c++, Class D is derived from class B. The class D does not contain any data members of its own . Does the class D require constructor? If yes, why? Explain with the help of a code example. 2. State true or false, giving proper reasons[3,5] (a) Virtual functions are used to create pointer to base class. (b) A pointer to base class cannot be made to point to objects of derived class. (c) Defining a derived class...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT