diff --git a/Geometry/Cone.js b/Geometry/Cone.js new file mode 100644 index 0000000000..742a527f41 --- /dev/null +++ b/Geometry/Cone.js @@ -0,0 +1,25 @@ +/** + * This class represents a circular cone and can calculate its volume and surface area + * https://en.wikipedia.org/wiki/Cone + * @constructor + * @param {number} baseRadius - The radius of the base of the cone. + * @param {number} height - The height of the cone + */ +export default class Cone { + constructor (baseRadius, height) { + this.baseRadius = baseRadius + this.height = height + } + + baseArea = () => { + return Math.pow(this.baseRadius, 2) * Math.PI + } + + volume = () => { + return this.baseArea() * this.height * 1 / 3 + } + + surfaceArea = () => { + return this.baseArea() + Math.PI * this.baseRadius * Math.sqrt(Math.pow(this.baseRadius, 2) + Math.pow(this.height, 2)) + } +} diff --git a/Geometry/Test/Cone.test.js b/Geometry/Test/Cone.test.js new file mode 100644 index 0000000000..3ab0010396 --- /dev/null +++ b/Geometry/Test/Cone.test.js @@ -0,0 +1,11 @@ +import Cone from '../Cone' + +const cone = new Cone(3, 5) + +test('The Volume of a cone with base radius equal to 3 and height equal to 5', () => { + expect(parseFloat(cone.volume().toFixed(2))).toEqual(47.12) +}) + +test('The Surface Area of a cone with base radius equal to 3 and height equal to 5', () => { + expect(parseFloat(cone.surfaceArea().toFixed(2))).toEqual(83.23) +}) pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy