Commit 30ed4828 authored by Chingiz's avatar Chingiz 💻

task 1 has been created

parent e072b5b3
"use strict";
class Figure {
constructor() {
this.area = 0;
this.figure = "figure";
}
}
class Rectangle extends Figure {
constructor(height, lenght) {
super();
this.figure = "Rectangle";
this.height = height;
this.lenght = lenght;
}
calculateArea() {
this.area = this.height * this.lenght;
}
}
class Triangle extends Figure {
constructor(height, baseline) {
super();
this.figure = "Triangle";
this.height = height;
this.baseline = baseline;
}
calculateArea() {
this.area = (this.height * this.baseline) / 2;
}
}
class Cerlce extends Figure {
constructor(radius) {
super();
this.figure = "Cercle";
this.radius = radius;
}
calculateArea() {
this.area = Math.PI * Math.sqrt(this.radius);
}
}
const Figures = [new Rectangle(20, 30),
new Triangle(40, 60),
new Cerlce(40)];
const printFigures = (arr) => {
arr.forEach(figure => {
figure.calculateArea();
console.log(`Area of ${figure.figure}:`, figure.area);
});
};
printFigures(Figures);
abstract class Figure{
public area: number = 0;
public figure: string = "figure";
public abstract calculateArea(): void;
}
class Rectangle extends Figure{
public height: number;
public lenght: number;
public override figure: string = "Rectangle";
constructor(height: number, lenght: number){
super();
this.height = height;
this.lenght = lenght;
}
public override calculateArea(): void {
this.area = this.height * this.lenght;
}
}
class Triangle extends Figure{
public height: number;
public baseline: number;
public override figure: string = "Triangle";
constructor(height: number, baseline: number){
super();
this.height = height;
this.baseline = baseline;
}
public override calculateArea(): void {
this.area = (this.height * this.baseline) / 2;
}
}
class Cerlce extends Figure{
public radius: number;
public override figure: string = "Cercle";
constructor(radius: number){
super();
this.radius = radius;
}
public override calculateArea(): void {
this.area = Math.PI * Math.sqrt(this.radius);
}
}
const Figures = [new Rectangle(20, 30),
new Triangle(40, 60),
new Cerlce(40)]
const printFigures = (arr: Figure[]) => {
arr.forEach(figure => {
figure.calculateArea();
console.log(`Area of ${figure.figure} :`, figure.area);
});
}
printFigures(Figures);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment