-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtask2.js
75 lines (66 loc) · 1.57 KB
/
task2.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
class Shape {
constructor(lenght, width) {
this.lenght = lenght;
this.width = width;
}
calculateArea() {
console.log(
`Area of the rectangle is ${this.lenght * this.width} meters sqaured`
);
}
calculatePerimeter() {
console.log(
`Perimeter of the shape is ${
(this.lenght + this.width) / 2
} meters sqaured`
);
}
}
class Circle extends Shape {
calculateArea() {
console.log(
`Area of the circle is ${(Math.PI * Math.pow(this.lenght, 2)).toFixed(
2
)} meters sqaured`
);
}
calculatePerimeter() {
console.log(
`Perimeter of the circle is ${(2 * Math.PI * this.lenght).toFixed(
2
)} meters sqaured`
);
}
}
class Triangle extends Shape {
constructor(lenght, width, extra) {
super(lenght, width);
this.extra = extra;
}
calculateArea() {
console.log(
`Area of the triangle is ${(0.5 * this.lenght * this.width).toFixed(
2
)} meters sqaured`
);
}
calculatePerimeter() {
console.log(
`Perimeter of the triangle is ${(
this.lenght +
this.width +
this.extra
).toFixed(2)} meters sqaured`
);
}
}
class Rectangle extends Shape {}
const circle1 = new Circle(3);
circle1.calculateArea();
circle1.calculatePerimeter();
const triangle1 = new Triangle(3, 2, 5);
triangle1.calculateArea();
triangle1.calculatePerimeter();
const rectangle1 = new Rectangle(3, 2);
rectangle1.calculateArea();
rectangle1.calculatePerimeter();