From 1c6d67d5bf5aca3f2c1b0514bf5837a21b8ff4d8 Mon Sep 17 00:00:00 2001 From: Roman Date: Thu, 4 Jun 2026 03:14:15 +0300 Subject: [PATCH 1/3] add task solution --- package-lock.json | 8 ++-- package.json | 2 +- src/figuresClasses.ts | 93 ++++++++++++++++++++++++++++++++++++++++--- 3 files changed, 93 insertions(+), 10 deletions(-) diff --git a/package-lock.json b/package-lock.json index a784e57dc..d3bc192e9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,7 +13,7 @@ "@babel/preset-env": "^7.24.8", "@babel/preset-typescript": "^7.24.7", "@mate-academy/eslint-config": "latest", - "@mate-academy/scripts": "^1.9.5", + "@mate-academy/scripts": "^2.1.3", "@mate-academy/students-ts-config": "latest", "@types/jest": "^29.5.12", "@types/node": "^20.14.10", @@ -2610,9 +2610,9 @@ } }, "node_modules/@mate-academy/scripts": { - "version": "1.9.5", - "resolved": "https://registry.npmjs.org/@mate-academy/scripts/-/scripts-1.9.5.tgz", - "integrity": "sha512-yNGwOpYK31yCqm6/l+8gZEBMlcbZthRQgtO1t1D7pNlCtfiCpLgfy9Wb17Hq3FndIGzCkMQnfKY1eDhMnxIkdQ==", + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/@mate-academy/scripts/-/scripts-2.1.3.tgz", + "integrity": "sha512-a07wHTj/1QUK2Aac5zHad+sGw4rIvcNl5lJmJpAD7OxeSbnCdyI6RXUHwXhjF5MaVo9YHrJ0xVahyERS2IIyBQ==", "dev": true, "license": "MIT", "dependencies": { diff --git a/package.json b/package.json index 2e0b6ee7e..8d69669b6 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ "@babel/preset-env": "^7.24.8", "@babel/preset-typescript": "^7.24.7", "@mate-academy/eslint-config": "latest", - "@mate-academy/scripts": "^1.9.5", + "@mate-academy/scripts": "^2.1.3", "@mate-academy/students-ts-config": "latest", "@types/jest": "^29.5.12", "@types/node": "^20.14.10", diff --git a/src/figuresClasses.ts b/src/figuresClasses.ts index 753711299..df3212b50 100644 --- a/src/figuresClasses.ts +++ b/src/figuresClasses.ts @@ -1,11 +1,94 @@ -export interface Figure {} +export interface Figure { + shape: 'triangle' | 'circle' | 'rectangle'; + color: 'red' | 'green' | 'blue'; + getArea(): number; +} + +export class Triangle implements Figure { + shape: 'triangle'; + + color: 'red' | 'green' | 'blue'; + + a: number; + + b: number; + + c: number; + + constructor( + color: 'red' | 'green' | 'blue', + a: number, + b: number, + c: number, + ) { + if (a <= 0 || b <= 0 || c <= 0) { + throw new Error('your error message'); + } + + if (Math.max(a, b, c) >= a + b + c - Math.max(a, b, c)) { + throw new Error('your error message'); + } + this.shape = 'triangle'; + this.color = color; + this.a = a; + this.b = b; + this.c = c; + } + + getArea(): number { + const s = (this.a + this.b + this.c) / 2; + const area = Math.sqrt(s * (s - this.a) * (s - this.b) * (s - this.c)); + + return Math.round(area * 100) / 100; + } +} -export class Triangle implements Figure {} +export class Circle implements Figure { + shape: 'circle'; -export class Circle implements Figure {} + color: 'red' | 'green' | 'blue'; -export class Rectangle implements Figure {} + radius: number; + + constructor(color: 'red' | 'green' | 'blue', radius: number) { + if (radius <= 0) { + throw new Error('your error message'); + } + + this.shape = 'circle'; + this.color = color; + this.radius = radius; + } + + getArea(): number { + return Math.floor(Math.PI * this.radius * this.radius * 100) / 100; + } +} + +export class Rectangle implements Figure { + shape: 'rectangle'; + + color: 'red' | 'green' | 'blue'; + + width: number; + + height: number; + + constructor(color: 'red' | 'green' | 'blue', width: number, height: number) { + if (width <= 0 || height <= 0) { + throw new Error('your error message'); + } + this.shape = 'rectangle'; + this.color = color; + this.width = width; + this.height = height; + } + + getArea(): number { + return this.width * this.height; + } +} export function getInfo(figure): string { - return typeof figure; + return `A ${figure.color} ${figure.shape} - ${figure.getArea()}`; } From e1870c3b3e230ca79481e91bd328d26bc2c00dc2 Mon Sep 17 00:00:00 2001 From: Roman Date: Thu, 4 Jun 2026 03:27:03 +0300 Subject: [PATCH 2/3] add task solution --- src/figuresClasses.ts | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/figuresClasses.ts b/src/figuresClasses.ts index df3212b50..ec38d4549 100644 --- a/src/figuresClasses.ts +++ b/src/figuresClasses.ts @@ -22,11 +22,14 @@ export class Triangle implements Figure { c: number, ) { if (a <= 0 || b <= 0 || c <= 0) { - throw new Error('your error message'); + throw new Error('The sides of a triangle must be positive numbers.'); } if (Math.max(a, b, c) >= a + b + c - Math.max(a, b, c)) { - throw new Error('your error message'); + throw new Error( + 'Sides 1, 2, and 3 cannot form a triangle.The longest' + + 'side must be less than the sum of the other two sides', + ); } this.shape = 'triangle'; this.color = color; @@ -39,7 +42,7 @@ export class Triangle implements Figure { const s = (this.a + this.b + this.c) / 2; const area = Math.sqrt(s * (s - this.a) * (s - this.b) * (s - this.c)); - return Math.round(area * 100) / 100; + return Math.floor(area * 100) / 100; } } @@ -52,7 +55,7 @@ export class Circle implements Figure { constructor(color: 'red' | 'green' | 'blue', radius: number) { if (radius <= 0) { - throw new Error('your error message'); + throw new Error('The radius of a circle must be a positive number'); } this.shape = 'circle'; @@ -76,7 +79,9 @@ export class Rectangle implements Figure { constructor(color: 'red' | 'green' | 'blue', width: number, height: number) { if (width <= 0 || height <= 0) { - throw new Error('your error message'); + throw new Error( + 'The width and height of a rectangle must be positive numbers', + ); } this.shape = 'rectangle'; this.color = color; From e2b509525f8f7d67d9a9c1ac366d5adf93e7deae Mon Sep 17 00:00:00 2001 From: Roman Date: Thu, 4 Jun 2026 03:41:51 +0300 Subject: [PATCH 3/3] add task solution --- src/figuresClasses.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/figuresClasses.ts b/src/figuresClasses.ts index ec38d4549..975ac7085 100644 --- a/src/figuresClasses.ts +++ b/src/figuresClasses.ts @@ -90,7 +90,7 @@ export class Rectangle implements Figure { } getArea(): number { - return this.width * this.height; + return Math.floor(this.width * this.height * 100) / 100; } }