-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgeometry-master.php
64 lines (49 loc) · 1.35 KB
/
geometry-master.php
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
<?php
abstract class AbstractGeometry {
abstract public function area(): int|float;
abstract public function perimeter(): int|float;
}
class Rectangle extends AbstractGeometry {
private int $width;
private int $height;
public function __construct(int $width, int $height) {
$this->width = $width;
$this->height = $height;
}
public function area(): int {
return $this->width * $this->height;
}
public function perimeter(): int {
return 2 * ($this->width + $this->height);
}
}
class Square extends AbstractGeometry {
private int $side;
public function __construct(int $side) {
$this->side = $side;
}
public function area(): int {
return $this->side ** 2;
}
public function perimeter(): int {
return 4 * $this->side;
}
}
class Triangle extends AbstractGeometry {
private int $a;
private int $b;
private int $c;
public function __construct(int $a, int $b, int $c) {
$this->a = $a;
$this->b = $b;
$this->c = $c;
}
public function area(): float {
$p = $this->perimeter() / 2;
return sqrt($p * ($p - $this->a) * ($p - $this->b) * ($p - $this->c));
}
public function perimeter(): int {
return $this->a + $this->b + $this->c;
}
}
echo (new Triangle(6,6,6))->area();