From fabfc03a5a3d5cf35d8f21bf7f95aebc6feefb79 Mon Sep 17 00:00:00 2001 From: Japoncio3k Date: Sun, 30 Oct 2022 11:25:03 -0300 Subject: [PATCH 1/2] Added cone class --- Geometry/Cone.js | 25 +++++++++++++++++++++++++ Geometry/Test/Cone.test.js | 11 +++++++++++ 2 files changed, 36 insertions(+) create mode 100644 Geometry/Cone.js create mode 100644 Geometry/Test/Cone.test.js diff --git a/Geometry/Cone.js b/Geometry/Cone.js new file mode 100644 index 0000000000..8f3bd1a160 --- /dev/null +++ b/Geometry/Cone.js @@ -0,0 +1,25 @@ +/** + * This class represents a circular cone and can calculate its volume and perimeter + * 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) +}) From cd813fd15c0511cc95d7bd52a48987698c995ab9 Mon Sep 17 00:00:00 2001 From: Japoncio3k Date: Sun, 30 Oct 2022 11:27:01 -0300 Subject: [PATCH 2/2] fixed comment --- Geometry/Cone.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Geometry/Cone.js b/Geometry/Cone.js index 8f3bd1a160..742a527f41 100644 --- a/Geometry/Cone.js +++ b/Geometry/Cone.js @@ -1,5 +1,5 @@ /** - * This class represents a circular cone and can calculate its volume and perimeter + * 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. 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