Question

Cones come in a few varieties, and we will consider the right circular cone. A cone...

Cones come in a few varieties, and we will consider the right circular cone. A cone with a circular base is a circular cone. A circular cone whose axis is perpendicular to the base is a right circular cone.

1.Create a new class called

.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.

2.Do not include a main method inside the class definition. As before, the class is not a complete program.

3.Let’s not worry about a Cone’s location in 3D space (yet!). If we ignore the right circular cone’s location, we can represent it with two variables: radius and height. Create instance variables for its radius and height.

4.A Cone has a public constructor which accepts one parameter for each of the instance variables. The body of the constructor should assign each parameter to its respective instance variable.

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

6.Create a method that returns the volume of the Cone. The formula for the volume V of a cone of radius r and height h =$#휋푟!ℎ.

7.Create a method that returns the slant height of the Cone. The formula for the slant height SH of a Cone of radius r and height h =√푟!+ℎ!.

8.Create a method that returns the surface area of the Cone. The formula for the surface area A of a Cone of radius r and height h=휋푟!+휋푟(√푟!+ℎ!)9.Create a toString() method which returns a String composed of the concatenation of the information in the Cone.

Homework Answers

Answer #1
Source code of the program and its working are given below.Comments are also given along with the code for better understanding.Screen shot of the code and output are also attached.If find any difficulty, feel free to ask in comment section. Please do upvote the answer.Thank you.

Working of the program

  • In Cone class. instance variable radius and height are declared
  • Constructor is defined to initialize these variables
  • getter methods are defined to get values.
  • setter methods are defined to set values.
  • getVolume() method is defined to calculate volume of cone.
  • Volume of a cone is calculated by using the formula  
  • getSlantHeight() method is defined to calculate slant height of the cone.
  • Slant height of a cone is calculated by using the formula   where r is the radius and h is the height
  • getSurfaceArea() method is defined to calculate surface area of the cone.
  • Surface area of a cone is calculated by using the formula  
  • toString() method of Object class is overridden to print cone information directly
  • Inside main class,an object of Cone class is created
  • It's information is printed
  • getVolume() ,getSlantHeight(),getSurfaceArea() methods are called and results are printed.

Source code

Cone class

/** Cone class represent right circular cone with radius and height
 * it contain methods to find volume,surface area,slant height
 * @author Your name
 * @version 1.0
 */
public class Cone {
    //instance variable declaration
    private double radius;
    private double height;
    //constructor to initialize variables
    public Cone(double radius, double height) {
        this.radius = radius;
        this.height = height;
    }
    //getter methods to get values
    public double getRadius() {
        return radius;
    }

    public double getHeight() {
        return height;
    }
    //setter methods to set values
    public void setRadius(double radius) {
        this.radius = radius;
    }

    public void setHeight(double height) {
        this.height = height;
    }
    //method to calculate volume
    public double getVolume()
    {
        double v=3.1416*radius*radius*height/3;
        return v;
    }
    //method to calculate slant height
    public double getSlantHeight()
    {
        double slantHeight=Math.sqrt(height*height+radius*radius);
        return slantHeight;
    }
    //method to calculate surface area
    public double getSurfaceArea()
    {
        double surfaceArea=3.1416*radius*(radius+Math.sqrt(height*height+radius*radius));
        return surfaceArea;
    }
    //overriding toString() method to print information of cone directly
    @Override
    public String toString() {
        return "\nRadius: "+radius+"\nHeight: "+height;
    }
}

Main class

public class Main {

    public static void main(String[] args) {
        //create Cone object
        Cone c=new Cone(8,12);
        //print cone information
        System.out.println(c);
        //display volume
        System.out.println("Volume: "+c.getVolume());
        //display slant height
        System.out.println("Slant height: "+c.getSlantHeight());
        //display surface area
        System.out.println("Surface area: "+c.getSurfaceArea());
    }
}

Screen shot of the code

Screen shot of the output

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Your solutions to this assignment MUST be implemented in functional style (using lambdas and streams), whenever...
Your solutions to this assignment MUST be implemented in functional style (using lambdas and streams), whenever possible. Needs help with part 3 only:    1.   Complete the Train constructor (verify that the data is correct)    a.   carrier must be one of the following: "Canadian National Railway", "Canadian Pacific Railway", "Hudson Bay Railway Co", "Quebec North Shore and Labrador Railway", "RailLink Canada", "Tshiuetin Rail Transportation", "Via Rail";    b.   trainNumber must be between 1 and 999;    c.   platform must...
Compile and execute the application. You will discover that is has a bug in it -...
Compile and execute the application. You will discover that is has a bug in it - the filled checkbox has no effect - filled shapes are not drawn. Your first task is to debug the starter application so that it correctly draws filled shapes. The bug can be corrected with three characters at one location in the code. Java 2D introduces many new capabilities for creating unique and impressive graphics. We’ll add a small subset of these features to the...
import java.util.ArrayList; /* Rules:         1. Allow Tester to iterate through all nodes using the...
import java.util.ArrayList; /* Rules:         1. Allow Tester to iterate through all nodes using the in-order traversal as the default.             This means, in Tester the following code should work for an instance of this class             called bst that is storing Student objects for the data:                 BinarySearchTree_Lab08<String> bst = new BinarySearchTree_Lab08<String>();                 bst.add("Man");       bst.add("Soda");   bst.add("Flag");                 bst.add("Home");   bst.add("Today");   bst.add("Jack");                ...
Homework Draw class diagrams for your HW4 - the Tetris Game shown below: Part 1: UML...
Homework Draw class diagrams for your HW4 - the Tetris Game shown below: Part 1: UML As a review, Here are some links to some explanations of UML diagrams if you need them. • https://courses.cs.washington.edu/courses/cse403/11sp/lectures/lecture08-uml1.pdf (Links to an external site.) • http://creately.com/blog/diagrams/class-diagram-relationships/ (Links to an external site.) • http://www.cs.bsu.edu/homepages/pvg/misc/uml/ (Links to an external site.) However you ended up creating the UML from HW4, your class diagram probably had some or all of these features: • Class variables: names, types, and...
This laboratory assignment involves implementing a data structure called a map. A map associates objects called...
This laboratory assignment involves implementing a data structure called a map. A map associates objects called keys with other objects called values. It is implemented as a Java class that uses arrays internally. 1. Theory. A map is a set of key-value pairs. Each key is said to be associated with its corresponding value, so there is at most one pair in the set with a given key. You can perform the following operations on maps. You can test if...